@memnexus-ai/mx-agent-cli 0.1.256 → 0.1.258

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.
@@ -91,20 +91,60 @@ fi
91
91
  # start in); mx-guard-hook.test.sh builds exactly that mutant and asserts every
92
92
  # #4803 test fails against it.
93
93
 
94
- # BASE_DIR — the directory the hook itself is standing in. `.cwd` is supplied by
95
- # the harness on the PreToolUse payload (same field reload-checkpoint.sh reads);
96
- # it is the session's default working directory, NOT the invoking command's, so
97
- # it is only ever the right answer for a bare `git push`. $PWD is the fallback
98
- # when the field is absent.
99
- BASE_DIR=$(echo "$INPUT" | jq -r '.cwd // empty' 2>/dev/null)
100
- if [ -z "$BASE_DIR" ] || [ ! -d "$BASE_DIR" ]; then
101
- BASE_DIR="$PWD"
94
+ # >>> SHARED push-target resolver v1 (#4803, #4808) — KEEP BYTE-IDENTICAL ─────
95
+ # Duplicated verbatim in mx-guard-hook.sh and ci-validate-hook.sh, exactly the
96
+ # way PUSH_RE already is, and pinned byte-for-byte by push-target-parity.test.sh.
97
+ # Deliberately NOT a sourced library: each hook must stay a standalone file (that
98
+ # is how settings.json invokes them and how bundle-config ships them), and two
99
+ # gates that fail independently are worth more than one shared file that can take
100
+ # both of them down at once.
101
+ #
102
+ # Reads: COMMAND (the tool command), INPUT (the PreToolUse payload), PUSH_RE
103
+ # Writes: MXPT_BASE_DIR — the directory the HOOK itself is standing in
104
+ # MXPT_BASE_TOP — git toplevel of that directory
105
+ # MXPT_DIRS — every DISTINCT local git toplevel this command pushes
106
+ # to, in command order; empty when every push is remote
107
+ # MXPT_TARGET_DIR — MXPT_DIRS[0], "" when there is none. Single-target
108
+ # callers read this; multi-target callers read MXPT_DIRS
109
+ # MXPT_TARGET_RAW — the path as it appeared in the command: the offending
110
+ # push's when resolution failed, otherwise the first
111
+ # local push's ("" for a bare push)
112
+ # MXPT_UNRESOLVED — why resolution failed, "" on success
113
+ # MXPT_REMOTE — 1 when at least one push executes on another host
114
+ # Acts: nothing. Each hook decides what to do with the verdict and says so in
115
+ # its own voice. There is deliberately no `exit` in this block: a
116
+ # resolver that exits takes the verdict away from the gate that owns it,
117
+ # and push-target-parity.test.sh fails if one appears.
118
+ #
119
+ # The two Should Fix findings from the security review of #4811 live here, both
120
+ # instances of the same "gate stands down without examining its subject" shape
121
+ # #4803 and #4808 are about:
122
+ # SF-1 remote-push detection substring-matched `ssh`/`scp` ANYWHERE in the
123
+ # command, and an unresolvable target then produced a silent skip while
124
+ # the LOCAL push still ran — a trailing `# over ssh tunnel` comment was
125
+ # enough. The remote token must now LEAD the segment the push belongs to,
126
+ # or lead the segment whose still-open quote encloses it (the
127
+ # `ssh host "cd X && git push"` form). Everything else fails CLOSED on
128
+ # the caller's loud path. Remote segments are skipped BEFORE resolution,
129
+ # so a remote push whose path happens to exist locally is never resolved
130
+ # against the wrong tree.
131
+ # SF-2 the walk stopped at the first push segment, so the second half of
132
+ # `git -C /treeA push && git -C /treeB push` was never examined. Every
133
+ # push segment is now collected and every distinct toplevel reported.
134
+ #
135
+ # `.cwd` is supplied by the harness on the PreToolUse payload (the same field
136
+ # reload-checkpoint.sh reads). It is the session's DEFAULT working directory, not
137
+ # the invoking command's, so it is only ever the right answer for a bare
138
+ # `git push`; $PWD is the fallback when the field is absent.
139
+ MXPT_BASE_DIR=$(echo "$INPUT" | jq -r '.cwd // empty' 2>/dev/null) || MXPT_BASE_DIR=""
140
+ if [ -z "$MXPT_BASE_DIR" ] || [ ! -d "$MXPT_BASE_DIR" ]; then
141
+ MXPT_BASE_DIR="$PWD"
102
142
  fi
103
143
 
104
144
  # Expand only the two path variables the harness sets identically in this
105
145
  # subprocess and in the tool command's shell. Anything else stays unexpanded and
106
146
  # is reported as unresolvable rather than guessed at.
107
- mxg_expand_known_vars() {
147
+ mxpt_expand_known_vars() {
108
148
  local p="$1"
109
149
  if [ -n "${CLAUDE_WORKTREE_PATH:-}" ]; then
110
150
  p="${p//\$\{CLAUDE_WORKTREE_PATH\}/$CLAUDE_WORKTREE_PATH}"
@@ -123,7 +163,7 @@ mxg_expand_known_vars() {
123
163
  printf '%s' "$p"
124
164
  }
125
165
 
126
- mxg_dequote() {
166
+ mxpt_dequote() {
127
167
  local p="$1"
128
168
  p="${p%\"}"; p="${p#\"}"
129
169
  p="${p%\'}"; p="${p#\'}"
@@ -131,166 +171,189 @@ mxg_dequote() {
131
171
  }
132
172
 
133
173
  # Walk the command's segments in order, tracking the last `cd <path>` seen, and
134
- # recording EVERY segment that begins a push. A `-C <path>` on a push segment
135
- # wins over the tracked `cd` (git applies it last). Segment splitting is the same
136
- # approximation the sibling guards use — it is a guardrail, not a parser, and
137
- # every ambiguity it cannot settle lands on the loud-block path below rather
138
- # than on a silent verdict.
139
- #
140
- # SF-2 (security review of this PR): the walk used to `break` at the first push
141
- # segment, so `git -C /treeA push && git -C /treeB push` linted treeA and let
142
- # treeB through unexamined — the same "verdict without examining the subject"
143
- # defect #4803 is about, one compound command later. Every push segment is now
144
- # collected and every distinct toplevel is linted; any failure blocks.
145
- #
146
- # SF-1 (same review): remote-push detection used to substring-match `ssh`/`scp`
147
- # ANYWHERE in the command, and an unresolvable target then exited 0 with no
148
- # linting while the LOCAL push still ran. A trailing comment was enough:
149
- # `cd /nonexistent ; git push origin b ` blocked, and the same
150
- # command plus `# over ssh tunnel` skipped. A remote push is now recognised only
151
- # when the ssh/scp/container-exec token is the LEAD command of the segment the
152
- # push belongs to (or of the segment whose still-open quote encloses it, which
153
- # is the `ssh host "cd X && git push"` form). Everything else fails CLOSED.
154
- MXG_PUSH_RAWS=() # one entry per push segment: the path text, "" = bare push
155
- MXG_PUSH_REMOTE=() # "1" iff that push segment runs on another host
156
- CD_RAW=""
157
- MXG_IN_QUOTE=0 # quote parity carried across segments
158
- MXG_REMOTE_CTX=0 # remote-launcher context of the current quoting level
159
- while IFS= read -r rawseg; do
160
- seg="${rawseg#"${rawseg%%[![:space:]]*}"}"
161
- seg="${seg#\(}"; seg="${seg#\{}"
162
- seg="${seg#"${seg%%[![:space:]]*}"}"
163
- if [[ "$seg" =~ ^(then|do|else)[[:space:]]+(.*)$ ]]; then
164
- seg="${BASH_REMATCH[2]}"
174
+ # recording EVERY segment that begins a push (SF-2). A `-C <path>` on a push
175
+ # segment wins over the tracked `cd` (git applies it last). Segment splitting is
176
+ # the same approximation the sibling guards use — it is a guardrail, not a
177
+ # parser, and every ambiguity it cannot settle lands on the caller's loud path
178
+ # rather than on a silent verdict.
179
+ MXPT_PUSH_RAWS=() # one entry per push segment: the path text, "" = bare push
180
+ MXPT_PUSH_REMOTE=() # "1" iff that push segment runs on another host
181
+ MXPT_CD_RAW=""
182
+ MXPT_IN_QUOTE=0 # quote parity carried across segments
183
+ MXPT_REMOTE_CTX=0 # remote-launcher context of the current quoting level
184
+ while IFS= read -r mxpt_rawseg; do
185
+ mxpt_seg="${mxpt_rawseg#"${mxpt_rawseg%%[![:space:]]*}"}"
186
+ mxpt_seg="${mxpt_seg#\(}"; mxpt_seg="${mxpt_seg#\{}"
187
+ mxpt_seg="${mxpt_seg#"${mxpt_seg%%[![:space:]]*}"}"
188
+ if [[ "$mxpt_seg" =~ ^(then|do|else)[[:space:]]+(.*)$ ]]; then
189
+ mxpt_seg="${BASH_REMATCH[2]}"
165
190
  fi
166
191
 
167
- # Remote context. Re-evaluated only at the top quoting level: a segment that
168
- # begins inside a quote opened by an earlier segment inherits that segment's
169
- # verdict, which is how the push inside `ssh host "..."` is recognised while
170
- # `ssh host uptime && git push` (quote closed, new lead token `git`) is not.
171
- MXG_SEG_IN_QUOTE=$MXG_IN_QUOTE
172
- if [ "$MXG_SEG_IN_QUOTE" -eq 0 ]; then
173
- MXG_REMOTE_CTX=0
174
- MXG_LEAD="${seg%%[[:space:]]*}"
175
- case "$MXG_LEAD" in
176
- ssh|scp|sftp|rsh) MXG_REMOTE_CTX=1 ;;
192
+ # Remote context (SF-1). Re-evaluated only at the top quoting level: a segment
193
+ # that begins inside a quote opened by an earlier segment inherits that
194
+ # segment's verdict, which is how the push inside `ssh host "..."` is
195
+ # recognised while `ssh host uptime && git push` (quote closed, new lead token
196
+ # `git`) is not.
197
+ MXPT_SEG_IN_QUOTE=$MXPT_IN_QUOTE
198
+ if [ "$MXPT_SEG_IN_QUOTE" -eq 0 ]; then
199
+ MXPT_REMOTE_CTX=0
200
+ MXPT_LEAD="${mxpt_seg%%[[:space:]]*}"
201
+ case "$MXPT_LEAD" in
202
+ ssh|scp|sftp|rsh) MXPT_REMOTE_CTX=1 ;;
177
203
  docker|podman|kubectl|oc)
178
- if [[ "$seg" =~ [[:space:]]exec([[:space:]]|$) ]]; then MXG_REMOTE_CTX=1; fi ;;
204
+ if [[ "$mxpt_seg" =~ [[:space:]]exec([[:space:]]|$) ]]; then MXPT_REMOTE_CTX=1; fi ;;
179
205
  esac
180
206
  fi
181
- MXG_SEG_REMOTE=$MXG_REMOTE_CTX
207
+ MXPT_SEG_REMOTE=$MXPT_REMOTE_CTX
182
208
 
183
209
  # Quote parity for the NEXT segment. Deliberately naive — an apostrophe inside
184
210
  # a word can skew it. Skew can only ever extend a remote context that a lead
185
211
  # token already established; with no remote lead the parity is unused and the
186
212
  # command still fails closed.
187
- MXG_Q="${rawseg//[^\"\']/}"
188
- if [ $(( ${#MXG_Q} % 2 )) -eq 1 ]; then
189
- MXG_IN_QUOTE=$(( 1 - MXG_IN_QUOTE ))
213
+ MXPT_Q="${mxpt_rawseg//[^\"\']/}"
214
+ if [ $(( ${#MXPT_Q} % 2 )) -eq 1 ]; then
215
+ MXPT_IN_QUOTE=$(( 1 - MXPT_IN_QUOTE ))
190
216
  fi
191
217
 
192
- if [[ "$seg" =~ ^cd[[:space:]]+([^[:space:]]+) ]]; then
193
- CD_RAW="${BASH_REMATCH[1]}"
218
+ if [[ "$mxpt_seg" =~ ^cd[[:space:]]+([^[:space:]]+) ]]; then
219
+ MXPT_CD_RAW="${BASH_REMATCH[1]}"
194
220
  continue
195
221
  fi
196
- if [[ "$seg" =~ $PUSH_RE ]]; then
197
- MXG_RAW=""
198
- if [[ "$seg" =~ (^|[[:space:]])-C[[:space:]]+([^[:space:]]+) ]]; then
199
- MXG_RAW="${BASH_REMATCH[2]}"
222
+ if [[ "$mxpt_seg" =~ $PUSH_RE ]]; then
223
+ MXPT_RAW=""
224
+ if [[ "$mxpt_seg" =~ (^|[[:space:]])-C[[:space:]]+([^[:space:]]+) ]]; then
225
+ MXPT_RAW="${BASH_REMATCH[2]}"
200
226
  fi
201
227
  # A relative `-C` is applied on top of the tracked `cd`, matching git.
202
- if [ -n "$MXG_RAW" ] && [ -n "$CD_RAW" ]; then
203
- case "$MXG_RAW" in
228
+ if [ -n "$MXPT_RAW" ] && [ -n "$MXPT_CD_RAW" ]; then
229
+ case "$MXPT_RAW" in
204
230
  /*|'~'*|'$'*) ;;
205
- *) MXG_RAW="$CD_RAW/$MXG_RAW" ;;
231
+ *) MXPT_RAW="$MXPT_CD_RAW/$MXPT_RAW" ;;
206
232
  esac
207
- elif [ -z "$MXG_RAW" ]; then
208
- MXG_RAW="$CD_RAW"
233
+ elif [ -z "$MXPT_RAW" ]; then
234
+ MXPT_RAW="$MXPT_CD_RAW"
209
235
  fi
210
- MXG_PUSH_RAWS+=("$MXG_RAW")
211
- MXG_PUSH_REMOTE+=("$MXG_SEG_REMOTE")
236
+ MXPT_PUSH_RAWS+=("$MXPT_RAW")
237
+ MXPT_PUSH_REMOTE+=("$MXPT_SEG_REMOTE")
212
238
  fi
213
- done < <(printf '%s\n' "$COMMAND" | sed -e 's/&&/\n/g' -e 's/||/\n/g' -e 's/[;&|]/\n/g')
239
+ done < <(printf '%s\n' "$COMMAND" | sed -e 's/&&/\n/g' -e 's/||/\n/g' -e 's/[;&|]/\n/g') || true
214
240
  # printf's trailing newline is deliberate: without it `read` hits EOF on the
215
- # final segment and the loop body never sees it, which silently drops the `-C`
216
- # on the common single-segment form `git -C <path> push`.
241
+ # final segment and the loop body never sees it, which silently drops the `-C` on
242
+ # the common single-segment form `git -C <path> push`. The `|| true` keeps the
243
+ # loop's own exit status away from ci-validate-hook.sh's fail-open ERR trap,
244
+ # where a non-zero status would turn this resolver into a silent `exit 0`.
217
245
 
218
246
  # The whole-command matcher fired but no segment did — the push is in a form the
219
247
  # splitter does not model. Treat it as a bare push against the hook's own tree
220
- # rather than skipping: linting something is the fail-closed side here.
221
- if [ "${#MXG_PUSH_RAWS[@]}" -eq 0 ]; then
222
- MXG_PUSH_RAWS=("")
223
- MXG_PUSH_REMOTE=(0)
248
+ # rather than skipping: reporting something is the fail-closed side here.
249
+ if [ "${#MXPT_PUSH_RAWS[@]}" -eq 0 ]; then
250
+ MXPT_PUSH_RAWS=("")
251
+ MXPT_PUSH_REMOTE=(0)
224
252
  fi
225
253
 
226
- BASE_TOP=$(git -C "$BASE_DIR" rev-parse --show-toplevel 2>/dev/null) || BASE_TOP="$BASE_DIR"
227
-
228
- # Resolve every push segment. Unresolvable + not remote = loud block; the hook
229
- # never falls back to linting whatever tree it happens to be standing in.
230
- MXG_DIRS=()
231
- for MXG_I in "${!MXG_PUSH_RAWS[@]}"; do
232
- TARGET_RAW="${MXG_PUSH_RAWS[$MXG_I]}"
254
+ MXPT_BASE_TOP=$(git -C "$MXPT_BASE_DIR" rev-parse --show-toplevel 2>/dev/null) || MXPT_BASE_TOP="$MXPT_BASE_DIR"
233
255
 
234
- if [ "${MXG_PUSH_REMOTE[$MXG_I]}" = "1" ]; then
235
- echo "⚠ mx-guard: a push in this command runs on a remote host — skipping local validation for it." >&2
256
+ # Resolve every push segment. Remote segments are skipped first and never
257
+ # resolved (SF-1); the first local segment that cannot be resolved stops
258
+ # resolution and is handed to the caller, which owns the loud path.
259
+ MXPT_DIRS=()
260
+ MXPT_TARGET_DIR=""
261
+ MXPT_TARGET_RAW=""
262
+ MXPT_UNRESOLVED=""
263
+ MXPT_REMOTE=0
264
+ for mxpt_i in "${!MXPT_PUSH_RAWS[@]}"; do
265
+ if [ "${MXPT_PUSH_REMOTE[$mxpt_i]}" = "1" ]; then
266
+ MXPT_REMOTE=1
236
267
  continue
237
268
  fi
238
-
239
- TARGET_DIR=""
240
- UNRESOLVED=""
241
- if [ -z "$TARGET_RAW" ]; then
269
+ if [ -n "$MXPT_UNRESOLVED" ]; then
270
+ continue
271
+ fi
272
+ mxpt_raw="${MXPT_PUSH_RAWS[$mxpt_i]}"
273
+ mxpt_dir=""
274
+ mxpt_why=""
275
+ if [ -z "$mxpt_raw" ]; then
242
276
  # Bare `git push` — the hook's own directory really is the push target.
243
- TARGET_DIR="$BASE_DIR"
277
+ mxpt_dir="$MXPT_BASE_DIR"
244
278
  else
245
- MXG_CAND=$(mxg_expand_known_vars "$(mxg_dequote "$TARGET_RAW")")
246
- case "$MXG_CAND" in
279
+ MXPT_CAND=$(mxpt_expand_known_vars "$(mxpt_dequote "$mxpt_raw")")
280
+ case "$MXPT_CAND" in
247
281
  *'$'*|*'`'*|*'*'*|*'?'*)
248
- UNRESOLVED="it contains a shell expression this hook cannot expand" ;;
282
+ mxpt_why="it contains a shell expression this hook cannot expand" ;;
249
283
  *)
250
- case "$MXG_CAND" in
284
+ case "$MXPT_CAND" in
251
285
  /*) ;;
252
- *) MXG_CAND="$BASE_DIR/$MXG_CAND" ;;
286
+ *) MXPT_CAND="$MXPT_BASE_DIR/$MXPT_CAND" ;;
253
287
  esac
254
- if [ ! -d "$MXG_CAND" ]; then
255
- UNRESOLVED="no such directory on this machine"
256
- elif ! TARGET_DIR=$(git -C "$MXG_CAND" rev-parse --show-toplevel 2>/dev/null); then
257
- UNRESOLVED="it is not inside a git work tree"
288
+ if [ ! -d "$MXPT_CAND" ]; then
289
+ mxpt_why="no such directory on this machine"
290
+ elif ! mxpt_dir=$(git -C "$MXPT_CAND" rev-parse --show-toplevel 2>/dev/null); then
291
+ mxpt_why="it is not inside a git work tree"
258
292
  fi ;;
259
293
  esac
260
294
  fi
261
-
262
- if [ -n "$UNRESOLVED" ]; then
263
- {
264
- echo "mx-guard: push BLOCKED — cannot identify the tree this push targets."
265
- echo ""
266
- echo " the push names: $TARGET_RAW"
267
- echo " problem: $UNRESOLVED"
268
- echo " would have run: mx-guard check in $BASE_DIR"
269
- echo ""
270
- echo " Linting $BASE_DIR would produce a verdict on a tree that is not the"
271
- echo " one being pushed — a pass would mean nothing and a failure would be"
272
- echo " someone else's. Re-run the push with a literal absolute path, e.g."
273
- echo " git -C /abs/path/to/worktree push <remote> <branch>"
274
- } >&2
275
- exit 2
276
- fi
277
-
278
- if [ "$TARGET_DIR" != "$BASE_TOP" ]; then
279
- echo "mx-guard: push targets $TARGET_DIR (shell cwd is $BASE_TOP) — linting the push target." >&2
295
+ if [ -n "$mxpt_why" ]; then
296
+ MXPT_TARGET_RAW="$mxpt_raw"
297
+ MXPT_UNRESOLVED="$mxpt_why"
298
+ continue
280
299
  fi
281
-
282
- MXG_SEEN=0
283
- for MXG_D in ${MXG_DIRS[@]+"${MXG_DIRS[@]}"}; do
284
- [ "$MXG_D" = "$TARGET_DIR" ] && MXG_SEEN=1
300
+ mxpt_seen=0
301
+ for mxpt_d in ${MXPT_DIRS[@]+"${MXPT_DIRS[@]}"}; do
302
+ if [ "$mxpt_d" = "$mxpt_dir" ]; then
303
+ mxpt_seen=1
304
+ fi
285
305
  done
286
- [ "$MXG_SEEN" -eq 0 ] && MXG_DIRS+=("$TARGET_DIR")
306
+ if [ "$mxpt_seen" -eq 0 ]; then
307
+ if [ "${#MXPT_DIRS[@]}" -eq 0 ]; then
308
+ MXPT_TARGET_RAW="$mxpt_raw"
309
+ fi
310
+ MXPT_DIRS+=("$mxpt_dir")
311
+ fi
287
312
  done
313
+ if [ -z "$MXPT_UNRESOLVED" ] && [ "${#MXPT_DIRS[@]}" -gt 0 ]; then
314
+ # shellcheck disable=SC2034 # read by the caller, not inside the block; a
315
+ # multi-target caller (mx-guard-hook.sh) reads MXPT_DIRS instead and leaves
316
+ # this one unread, which is what SC2034 sees.
317
+ MXPT_TARGET_DIR="${MXPT_DIRS[0]}"
318
+ fi
319
+ # <<< SHARED push-target resolver v1
320
+
321
+ # The resolver computes; the verdict is this hook's, and this hook says it in its
322
+ # own voice. A remote push cannot be validated from here, and blocking it would
323
+ # be a false block invented by the resolver rather than a real finding.
324
+ if [ "$MXPT_REMOTE" = "1" ]; then
325
+ echo "⚠ mx-guard: a push in this command runs on a remote host — skipping local validation for it." >&2
326
+ fi
327
+
328
+ # Unresolvable and not remote: block. The hook never falls back to linting
329
+ # whatever tree it happens to be standing in.
330
+ if [ -n "$MXPT_UNRESOLVED" ]; then
331
+ {
332
+ echo "mx-guard: push BLOCKED — cannot identify the tree this push targets."
333
+ echo ""
334
+ echo " the push names: $MXPT_TARGET_RAW"
335
+ echo " problem: $MXPT_UNRESOLVED"
336
+ echo " would have run: mx-guard check in $MXPT_BASE_DIR"
337
+ echo ""
338
+ echo " Linting $MXPT_BASE_DIR would produce a verdict on a tree that is not the"
339
+ echo " one being pushed — a pass would mean nothing and a failure would be"
340
+ echo " someone else's. Re-run the push with a literal absolute path, e.g."
341
+ echo " git -C /abs/path/to/worktree push <remote> <branch>"
342
+ } >&2
343
+ exit 2
344
+ fi
288
345
 
289
346
  # Every push in the command was remote — nothing local to lint.
290
- if [ "${#MXG_DIRS[@]}" -eq 0 ]; then
347
+ if [ "${#MXPT_DIRS[@]}" -eq 0 ]; then
291
348
  exit 0
292
349
  fi
293
350
 
351
+ for MXG_D in "${MXPT_DIRS[@]}"; do
352
+ if [ "$MXG_D" != "$MXPT_BASE_TOP" ]; then
353
+ echo "mx-guard: push targets $MXG_D (shell cwd is $MXPT_BASE_TOP) — linting the push target." >&2
354
+ fi
355
+ done
356
+
294
357
  # Run mx-guard check (change-aware — only checks files on current branch).
295
358
  # Route its output to stderr so its findings are visible on the block path.
296
359
  {
@@ -303,14 +366,14 @@ fi
303
366
  # #4803 region around. MXG_PRIOR_FAIL carries the earlier verdicts past the
304
367
  # region boundary so "any target fails => push blocked" holds.
305
368
  MXG_PRIOR_FAIL=0
306
- MXG_LAST=$(( ${#MXG_DIRS[@]} - 1 ))
307
- for MXG_I in "${!MXG_DIRS[@]}"; do
369
+ MXG_LAST=$(( ${#MXPT_DIRS[@]} - 1 ))
370
+ for MXG_I in "${!MXPT_DIRS[@]}"; do
308
371
  [ "$MXG_I" -eq "$MXG_LAST" ] && break
309
- if ! ( cd "${MXG_DIRS[$MXG_I]}" && mx-guard check >&2 ); then
372
+ if ! ( cd "${MXPT_DIRS[$MXG_I]}" && mx-guard check >&2 ); then
310
373
  MXG_PRIOR_FAIL=1
311
374
  fi
312
375
  done
313
- TARGET_DIR="${MXG_DIRS[$MXG_LAST]}"
376
+ TARGET_DIR="${MXPT_DIRS[$MXG_LAST]}"
314
377
 
315
378
  if ! cd "$TARGET_DIR"; then
316
379
  echo "mx-guard: push BLOCKED — could not enter $TARGET_DIR to validate it." >&2
@@ -37,6 +37,10 @@
37
37
  {
38
38
  "type": "command",
39
39
  "command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/named-memory-write-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
40
+ },
41
+ {
42
+ "type": "command",
43
+ "command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/gh-pr-edit-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
40
44
  }
41
45
  ]
42
46
  }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * mx-agent pr set-body <pr> --body-file <path> | --body <text>
3
+ *
4
+ * A PR-body write that CANNOT silently no-op.
5
+ *
6
+ * WHY THIS EXISTS. Documented twice — the sub-case "a tool that reports success
7
+ * and does nothing" in
8
+ * mx-agent-system/coe/nominations/2026-07-27-controls-report-healthy-while-doing-nothing-appendix.md
9
+ * and the instance on PR #4616 — and it bit another team again afterwards.
10
+ * `gh pr edit` is broken repo-wide on the `gh` we ship
11
+ * (2.46.0, Debian trixie, `.devcontainer/Dockerfile:21`, unpinned). Its
12
+ * `PullRequestByNumber` prefetch unconditionally selects `projectCards`;
13
+ * GitHub returns the whole `repository.pullRequest` node as null plus a
14
+ * NOT_FOUND error, and gh aborts BEFORE sending the mutation. It exits 1 and
15
+ * prints only a GraphQL notice that Projects (classic) "is being deprecated" —
16
+ * nothing about the body, the edit, or the failure. Upstream fixed this in
17
+ * v2.73.0 (May 2025) via feature detection; Debian trixie has no such
18
+ * candidate. Measured 2026-08-01 on PR #4785: `--add-label`, `--add-assignee`,
19
+ * `--milestone` and `--remove-label` all fail identically, so the defect is the
20
+ * prefetch and not any one flag.
21
+ *
22
+ * WHY VERIFICATION IS THE POINT, NOT THE EXIT STATUS. This defect has bitten
23
+ * twice. The second time (PR #4616) the exit status was never wrong — checking
24
+ * `$?`, dropping a `tail -1`, or adding `set -o pipefail` would all have
25
+ * passed while nothing was written. "Don't discard exit statuses" is the wrong
26
+ * lesson. The only check that catches a write that reports success and does
27
+ * nothing is reading the artifact's content back.
28
+ *
29
+ * TWO CHECKS, DELIBERATELY:
30
+ * 1. The PATCH response's own `body` field. That is the server's account of
31
+ * what it stored, returned by the same request that stored it, so unlike a
32
+ * re-read it cannot race with propagation.
33
+ * 2. A second, fresh GET. This catches the case the response check cannot: a
34
+ * write that the API acknowledged but that is not what the PR now serves
35
+ * (a concurrent overwrite, a rejected-but-200 path).
36
+ * Neither check alone is sufficient — check 1 can only see what one request
37
+ * claims, and check 2 alone is the read-back-too-early failure (#F4) that
38
+ * returns your own unpropagated write. Any mismatch in either exits non-zero
39
+ * with a diff. Success is printed only after both have passed.
40
+ */
41
+ import { type SpawnSyncFn } from '../lib/gh-remote.js';
42
+ export interface PrSetBodyOptions {
43
+ /** PR number, as given on the command line. */
44
+ pr: string;
45
+ /** Path to a file holding the new body. Mutually exclusive with `body`. */
46
+ bodyFile?: string;
47
+ /** Literal body text. Mutually exclusive with `bodyFile`. */
48
+ body?: string;
49
+ /** Override `owner/repo` (default: resolved from the git remote). */
50
+ repo?: string;
51
+ /** Working directory used to resolve the remote. */
52
+ cwd?: string;
53
+ /** Suppress the success line. Failures always print. */
54
+ quiet?: boolean;
55
+ }
56
+ /**
57
+ * Thrown for every failure path so the caller exits non-zero with one readable
58
+ * message. `message` already contains the diff when there is one.
59
+ */
60
+ export declare class PrSetBodyError extends Error {
61
+ constructor(message: string);
62
+ }
63
+ /**
64
+ * First-divergence diff, bounded. Prints the line number where the two texts
65
+ * first differ with both versions, plus the line counts, which is what tells
66
+ * you whether the write landed partially, not at all, or as something else.
67
+ * Lines are truncated so a 40 kB body cannot flood the terminal, and control
68
+ * characters are stripped: this text comes back from the API and is shown in a
69
+ * failure message, so it is treated as untrusted.
70
+ */
71
+ export declare function renderBodyDiff(intended: string, actual: string): string;
72
+ export declare function validateOwnerRepo(repo: string, source: string): string;
73
+ export declare function runPrSetBody(options: PrSetBodyOptions, spawn?: SpawnSyncFn): Promise<void>;
74
+ //# sourceMappingURL=pr-set-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr-set-body.d.ts","sourceRoot":"","sources":["../../src/commands/pr-set-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAKH,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAcD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAwBvE;AAoBD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgBtE;AA6CD,wBAAsB,YAAY,CAChC,OAAO,EAAE,gBAAgB,EACzB,KAAK,GAAE,WAAuB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAiFf"}