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

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.
@@ -18,7 +18,14 @@
18
18
  #
19
19
  # ESCAPE HATCH: prefix the command with `GIT_EXPERT=1` to run a genuinely-needed
20
20
  # destructive git op deliberately (e.g. GIT_EXPERT=1 git reset --hard <sha>).
21
- # The escape is intentional friction, not a lock.
21
+ # The escape is intentional friction, not a lock. PREFIX means prefix (#4804):
22
+ # the token must sit in the environment-assignment position at the start of the
23
+ # SAME command segment as the operation it clears, which is where a shell would
24
+ # apply it. The token appearing anywhere else in the command — inside quoted
25
+ # prose, in a comment, in a file being written, in a different segment — clears
26
+ # nothing. Before #4804 it cleared everything, which made `echo 'see
27
+ # GIT_EXPERT=1 docs' && git stash` a working bypass and made the audit log
28
+ # unreadable as evidence.
22
29
  # OVERRIDE AUDIT (2026-07-31 false alarm): an override that clears a real block is
23
30
  # appended to ~/.mx-agent/logs/git-guard-override.jsonl before the command runs,
24
31
  # so "the guard never fired" and "the guard fired and was overridden" are
@@ -85,24 +92,60 @@ fi
85
92
  # instead of blocking. A GIT_EXPERT=1 command that matches nothing is not an
86
93
  # override of anything and is not logged.
87
94
  #
88
- # LOG FIDELITY (#4804, part 1 of 2). OVERRIDE below is a WHOLE-COMMAND test and
89
- # still governs the allow/deny decision exactly as before — this commit changes
90
- # no boundary. What it changes is what gets WRITTEN: a record is appended only
91
- # when the override token and the pattern that matched occur in the SAME command
92
- # segment (SEG_OVERRIDE, set in check_segment). The whole-command test made the
93
- # log useless as evidence — a read-only command that merely mentions both the
94
- # token and a destructive verb somewhere in its text (an agent writing about the
95
- # guard, a probe script being edited) produced a record indistinguishable from a
96
- # genuine override. All four records in the live log were produced that way; none
97
- # was a real override. Same-segment is the weakest condition that separates "the
98
- # token was applied to this command" from "the token appears somewhere on the
99
- # line", and it is decision-neutral, so it needs no boundary re-verification.
100
- OVERRIDE_RE='(^|[^A-Za-z_])GIT_EXPERT=1(\s|$)'
101
- OVERRIDE=0
102
- if echo "$COMMAND" | grep -qE "$OVERRIDE_RE"; then
103
- OVERRIDE=1
104
- fi
105
- # Set per segment by check_segment; consumed by refuse() for logging only.
95
+ # OVERRIDE DETECTION IS SEGMENT-ANCHORED AND SEGMENT-SCOPED (#4804). Two rules,
96
+ # both required:
97
+ # 1. the token must sit where a shell would actually apply it — at the start of
98
+ # a command segment, in the environment-assignment position, the same way
99
+ # GITSEG anchors `git`; and
100
+ # 2. it must be in the SAME segment as the pattern it is claimed to clear.
101
+ # Before this, OVERRIDE was an unanchored, unscoped grep of the whole command,
102
+ # which meant any command containing the eleven characters `GIT_EXPERT=1`
103
+ # anywhere — inside quoted prose, in a comment, in a file being written, in a
104
+ # later segment — turned off the guard for the entire command. Measured:
105
+ # echo 'see GIT_EXPERT=1 docs' && git stash -> was ALLOWED, now BLOCKED
106
+ # # a comment naming GIT_EXPERT=1 \n git reset --hard abc -> was ALLOWED, now BLOCKED
107
+ # That was the cheapest bypass in the file, cheaper than the three bypass classes
108
+ # the SCOPE header documents as knowingly out of scope, and unlike those it could
109
+ # be tripped by accident — an agent writing a report about the guard disabled it
110
+ # for the same command. It also destroyed the audit log's meaning; see part 1.
111
+ #
112
+ # OVSEG IS ANCHORED AT `^` ONLY — it is deliberately NOT a copy of GITSEG's
113
+ # boundary class (MF-1, security review 2026-08-01). Every string OVSEG is tested
114
+ # against is already exactly one command segment on its own line (strip_heredocs
115
+ # then strip_sink_quotes emit one segment per line, and grep -E is line-oriented),
116
+ # so `^` IS the segment boundary. The earlier revision reused GITSEG's
117
+ # `(^|[;&|({`]|...)` prefix, which named FIVE boundaries the segmenter never
118
+ # splits on — a single `&`, `(`, `{`, a backtick, and `$(`. A token after any of
119
+ # them sat mid-line inside one segment and still matched, so all of these
120
+ # overrode the guard: `git stash & GIT_EXPERT=1 true`,
121
+ # `git stash $(GIT_EXPERT=1 true)`, `git stash # note (GIT_EXPERT=1 ...)`, and a
122
+ # `--body "run (GIT_EXPERT=1 git stash) now"` escalation. Measured, all four
123
+ # ALLOWED before this change, all four BLOCK after it.
124
+ #
125
+ # ASYMMETRY — this is the rule that decides which regex gets which treatment.
126
+ # GITSEG (block detection) MAY over-match: a false positive costs one blocked
127
+ # command that GIT_EXPERT=1 clears, so it stays permissive about boundaries.
128
+ # OVSEG (override detection) MUST under-match: a false positive turns the guard
129
+ # OFF, which is the failure the guard exists to prevent, so it recognises only
130
+ # the position a shell would actually treat as an assignment. Never "fix" a
131
+ # missed override by widening OVSEG toward GITSEG; widen the SEGMENTER instead,
132
+ # so the token and the verb land in different segments.
133
+ #
134
+ # Preceding leading redirections, other env assignments, and launcher words that
135
+ # exec their argv are tolerated, so `FOO=1 GIT_EXPERT=1 git ...` and
136
+ # `GIT_EXPERT=1 sudo git ...` still override. `echo GIT_EXPERT=1 ...` does not:
137
+ # `echo` is not a launcher, so the token is an argument, not an assignment.
138
+ #
139
+ # PROPAGATION TO DERIVED SEGMENTS: a segment that a shell WILL execute inherits
140
+ # its parent's override — the quoted payload of an executor (`GIT_EXPERT=1 bash
141
+ # -c "git reset --hard"`) and the kept body of a shell heredoc (`GIT_EXPERT=1
142
+ # bash <<EOF ... EOF`). Those bodies are emitted as separate scan segments, so
143
+ # without propagation a genuine, correctly-anchored override would stop working
144
+ # on them. The token still has to be anchored on the parent, so this is not a
145
+ # way back in for prose.
146
+ OVSEG='^[[:space:]]*([0-9]*[<>][^[:space:]]*[[:space:]]+|[A-Za-z_][A-Za-z0-9_]*=[^[:space:];&|]*[[:space:]]+|(sudo|env|nice|nohup|time|timeout|ionice|stdbuf|command|xargs|setsid|doas|nsenter)[[:space:]]+([0-9]+[[:space:]]+)?)*GIT_EXPERT=1([[:space:]]|$)'
147
+ # Set per segment by check_segment; consumed by refuse() for the decision AND the
148
+ # audit record. There is no whole-command override state any more.
106
149
  SEG_OVERRIDE=0
107
150
 
108
151
  # --- override audit log (fail-open, side-effect only) -------------------------
@@ -200,10 +243,46 @@ log_override() {
200
243
  # itself is always preserved (it may hold a real git verb before the `<<`).
201
244
  # Covers the common forms: `<<EOF`, `<<-EOF`, `<<"EOF"`, `<<'EOF'`, `<< EOF`.
202
245
  strip_heredocs() {
203
- awk '
246
+ awk -v ovre="$OVSEG" '
247
+ # The heredoc OPERATOR LINE may hold several command segments
248
+ # (`echo "..."; bash <<EOF`). Only the segment that actually contains the
249
+ # `<<` is the command that executes the body, so only that segment can carry
250
+ # an override for it (MF-3). Returns the operator line from just after the
251
+ # last separator preceding the `<<` to end of line. Separators are the same
252
+ # set the segmenter in strip_sink_quotes uses (`;` `&` `&&` `|` `||`) — for
253
+ # the two-character forms the second character simply wins, which lands the
254
+ # start in the same place.
255
+ #
256
+ # The scan is QUOTE-AWARE, character for character the same way the segmenter
257
+ # in strip_sink_quotes is (MF-4). Only an UNQUOTED separator ends a segment;
258
+ # a `;`, `&` or `|` inside a quoted ARGUMENT is an ordinary character that no
259
+ # shell treats as a boundary. Scanning without quote awareness was a bypass:
260
+ # the separator inside the quotes moved the derived segment start forward and
261
+ # parked an inert positional argument at position 1, where the ^-anchored
262
+ # OVSEG matched it as if it were an environment assignment —
263
+ # bash -s "x; GIT_EXPERT=1 note" <<EOF ... git reset --hard origin/main ... EOF
264
+ # `bash -s` reads its script from STDIN, so the heredoc body executes while
265
+ # the token is never an assignment at all. ALLOWED before this change (and it
266
+ # wrote an audit record claiming a sanctioned override), BLOCKS after it.
267
+ # The two functions must agree on what counts as a separator: divergence
268
+ # between them is what made MF-1 exploitable, so keep this loop and the one
269
+ # at the top of strip_sink_quotes in step.
270
+ function op_segment(line, pos, i, c, st, isq, idq) {
271
+ st = 1; isq = 0; idq = 0
272
+ for (i = 1; i < pos; i++) {
273
+ c = substr(line, i, 1)
274
+ if (isq) { if (c == "'"'"'") isq = 0; continue }
275
+ if (idq) { if (c == "\\") { i++; continue }; if (c == "\"") idq = 0; continue }
276
+ if (c == "'"'"'") { isq = 1; continue }
277
+ if (c == "\"") { idq = 1; continue }
278
+ if (c == ";" || c == "&" || c == "|") st = i + 1
279
+ }
280
+ return substr(line, st)
281
+ }
204
282
  !inbody {
205
283
  line = $0
206
284
  if (match(line, /<<[-]?[[:space:]]*["'"'"']?[A-Za-z_][A-Za-z0-9_]*["'"'"']?/)) {
285
+ hpos = RSTART
207
286
  d = substr(line, RSTART, RLENGTH)
208
287
  gsub(/<<[-]?[[:space:]]*["'"'"']?/, "", d)
209
288
  gsub(/["'"'"'].*/, "", d)
@@ -214,6 +293,15 @@ strip_heredocs() {
214
293
  if (line ~ /(^|[^[:alnum:]_])(bash|sh|zsh|dash|ksh|eval|source)([^[:alnum:]_]|$)/) keepbody = 1
215
294
  if (line ~ /(^|[[:space:]])\.[[:space:]]/) keepbody = 1
216
295
  if (line ~ /\|[^|]*(bash|sh|zsh|dash|ksh|eval)([^[:alnum:]_]|$)/) keepbody = 1
296
+ # A kept body is executed BY the operator-line SEGMENT that holds the
297
+ # `<<`, so only an anchored override on THAT segment applies to it
298
+ # (#4804 / MF-3). Testing the whole line was a bypass: an unrelated
299
+ # earlier segment supplied the token, e.g.
300
+ # echo "(GIT_EXPERT=1 note)"; bash <<EOF ... git reset --hard ... EOF
301
+ # ALLOWED before this change, BLOCKS after it. This runs before
302
+ # segmentation and before sink-quote blanking, which is why the operator
303
+ # line has to be segmented here rather than trusted whole.
304
+ ovbody = (op_segment(line, hpos) ~ ovre) ? 1 : 0
217
305
  }
218
306
  print line
219
307
  next
@@ -221,8 +309,8 @@ strip_heredocs() {
221
309
  {
222
310
  t = $0
223
311
  gsub(/^[[:space:]]+/, "", t)
224
- if (t == delim) { inbody = 0; keepbody = 0; next }
225
- if (keepbody) print $0
312
+ if (t == delim) { inbody = 0; keepbody = 0; ovbody = 0; next }
313
+ if (keepbody) { if (ovbody) print "GIT_EXPERT=1 " $0; else print $0 }
226
314
  # else: inert-consumer body — data, not a command; drop it from the scan
227
315
  }
228
316
  '
@@ -240,7 +328,7 @@ strip_heredocs() {
240
328
  # are not blanked (its output feeds the executor). Fail-safe: unknown
241
329
  # commands keep quotes intact (no blanking, no extraction).
242
330
  strip_sink_quotes() {
243
- awk '
331
+ awk -v ovre="$OVSEG" '
244
332
  function get_lead_cmd(seg, s) {
245
333
  s = seg; gsub(/^[[:space:]]+/, "", s)
246
334
  while (match(s, /^[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*[[:space:]]+/))
@@ -333,6 +421,14 @@ function extract_quotes(seg, n, i, c, ct, isq, idq, res) {
333
421
  sp = 0; sl = 1; st = ""
334
422
  if (c == ";") { sp = 1; st = "seq" }
335
423
  else if (c == "&" && i < n && substr(line, i+1, 1) == "&") { sp = 1; sl = 2; st = "seq" }
424
+ # Single `&` backgrounds the command to its LEFT and starts a new one to
425
+ # its right — two separate shell commands, exactly like `;` (MF-1). It was
426
+ # missing here while GITSEG and the old OVSEG both named `&` a boundary,
427
+ # so `git stash & GIT_EXPERT=1 true` arrived as ONE segment carrying both
428
+ # the verb and the token and the override applied to a command the token
429
+ # was never part of. Splitting here puts the backgrounded verb in its own
430
+ # segment with no token, which blocks.
431
+ else if (c == "&") { sp = 1; st = "seq" }
336
432
  else if (c == "|" && i < n && substr(line, i+1, 1) == "|") { sp = 1; sl = 2; st = "seq" }
337
433
  else if (c == "|") { sp = 1; st = "pipe" }
338
434
  if (sp) {
@@ -358,7 +454,15 @@ function extract_quotes(seg, n, i, c, ct, isq, idq, res) {
358
454
  cmd = get_lead_cmd(segs[s])
359
455
  if (is_exec(cmd) || pxe[s]) {
360
456
  ex = extract_quotes(segs[s])
361
- if (ex != "") print ex
457
+ if (ex != "") {
458
+ # An executor payload is executed BY this segment, so an
459
+ # anchored override on the segment applies to it (#4804).
460
+ # Stamp each extracted line, which is its own scan segment.
461
+ if (segs[s] ~ ovre) {
462
+ nx = split(ex, xa, "\n")
463
+ for (k = 1; k <= nx; k++) print "GIT_EXPERT=1 " xa[k]
464
+ } else print ex
465
+ }
362
466
  }
363
467
  }
364
468
  }
@@ -368,22 +472,41 @@ function extract_quotes(seg, n, i, c, ct, isq, idq, res) {
368
472
 
369
473
  SCAN=$(printf '%s' "$COMMAND" | strip_heredocs)
370
474
 
475
+ # Set when an override clears a real match. It records that the scan CONTINUED
476
+ # past a cleared pattern rather than exiting at it (MF-2) — the exit status is 0
477
+ # either way, so this exists to make the cleared-but-continued state readable in
478
+ # a trace and greppable by a future check. Assigned in refuse(), read at the
479
+ # final exit.
480
+ CLEARED=0
481
+
371
482
  refuse() {
372
483
  local what="$1"
373
484
 
374
- # Override in effect: record what it cleared, then allow. Silent on stdout and
375
- # stderr — the allow contract is "exit 0, no output".
485
+ # Override in effect: record what it cleared, then RETURN — do not exit.
486
+ # Silent on stdout and stderr; the allow contract is "exit 0, no output".
376
487
  #
377
- # The ALLOW is decided by the whole-command OVERRIDE (unchanged). The RECORD is
378
- # written only when the token sits in the same segment as the pattern that
379
- # matched (#4804): a command whose token and pattern are in different segments
380
- # is still allowed exactly as before, but it is not evidence of an override and
381
- # must not be written down as one.
382
- if [[ "$OVERRIDE" -eq 1 ]]; then
383
- if [[ "$SEG_OVERRIDE" -eq 1 ]]; then
384
- log_override "$what"
385
- fi
386
- exit 0
488
+ # RETURN, NOT EXIT (MF-2, security review 2026-08-01). This used to
489
+ # `exit 0` here, which ended the whole scan at the FIRST cleared segment.
490
+ # An override anchored on segment 1 therefore let every later segment through
491
+ # unscanned and unlogged, which is precisely the whole-command override #4804
492
+ # was opened to remove — reintroduced by the exit rather than by the regex.
493
+ # Measured: `GIT_EXPERT=1 git stash && git reset --hard origin/main` ALLOWED
494
+ # the reset, with one audit line naming only the stash. Now each pattern is
495
+ # judged against its own segment: the stash is cleared and logged, the reset
496
+ # has no token in its segment and blocks. A command with a genuine override on
497
+ # every segment produces one audit line PER cleared pattern, so the log stays
498
+ # a complete record of what was cleared rather than a record of the first
499
+ # thing cleared.
500
+ #
501
+ # Both the allow and the record come from the same per-segment condition
502
+ # (#4804): the token is anchored at the start of the segment, in the
503
+ # environment-assignment position, AND is in the segment whose pattern
504
+ # matched. A token elsewhere in the command clears nothing and is not
505
+ # written down.
506
+ if [[ "$SEG_OVERRIDE" -eq 1 ]]; then
507
+ log_override "$what"
508
+ CLEARED=1
509
+ return 0
387
510
  fi
388
511
 
389
512
  {
@@ -452,15 +575,20 @@ GITSEG='(^|[;&|({`]|\s(then|do|else)\s)\s*([0-9]*[<>][^[:space:]]*\s+|[A-Za-z_][
452
575
  # allow-form matched elsewhere on the line. strip_sink_quotes splits SCAN on
453
576
  # unquoted shell separators (`;` `&&` `||` `|`), blanks quoted content in sink
454
577
  # segments, extracts quoted content from executor segments as additional lines,
455
- # and emits one segment per line. refuse() exits, so the first offending
456
- # segment blocks.
578
+ # and emits one segment per line.
579
+ #
580
+ # TERMINATION (MF-2): refuse() exits only on a BLOCK, so the first offending
581
+ # segment with no override in it still ends the scan at exit 2. A CLEARED
582
+ # override terminates nothing — the remaining pattern checks in that segment and
583
+ # every remaining segment are still evaluated, so a later un-overridden segment
584
+ # can still block, and each cleared pattern gets its own audit line.
457
585
  check_segment() {
458
586
  local seg="$1"
459
587
 
460
- # Does the override token appear in THIS segment (#4804)? Logging-only in this
461
- # revision: refuse() still decides allow/deny from the whole-command OVERRIDE.
588
+ # Is there an anchored override token in THIS segment (#4804)? This decides
589
+ # both whether a match is refused and whether it is recorded.
462
590
  SEG_OVERRIDE=0
463
- if printf '%s' "$seg" | grep -qE "$OVERRIDE_RE"; then
591
+ if printf '%s' "$seg" | grep -qE "$OVSEG"; then
464
592
  SEG_OVERRIDE=1
465
593
  fi
466
594
 
@@ -501,4 +629,9 @@ while IFS= read -r _seg; do
501
629
  check_segment "$_seg"
502
630
  done < <(printf '%s\n' "$SCAN" | strip_sink_quotes)
503
631
 
632
+ # Reached the end of the scan: either nothing matched, or every match was cleared
633
+ # by an anchored, same-segment override (CLEARED=1, one audit line per cleared
634
+ # pattern). Both are allow. Under `set -u` this also fails loudly if a future
635
+ # edit drops the CLEARED initialisation, rather than allowing silently.
636
+ [[ "$CLEARED" -eq 1 ]] || true
504
637
  exit 0
@@ -10,7 +10,7 @@ Use this skill before closing an iteration, opening a PR, merging a PR, or handi
10
10
  4. Confirm tests, fixtures, replays, screenshots, or manual checks appropriate to the risk were completed.
11
11
  5. Confirm hook output and command failures were interpreted from exit status and logs, not from noisy reminder text alone.
12
12
  6. Confirm state memories, issue comments, or claim ledgers were updated when the work changed project knowledge.
13
- 7. Confirm every GitHub issue and PR referenced in a team-owned tracking document was reconciled against its real state with `gh issue view` / `gh pr view` before that document is cited in a product-owner-facing decision or status report. Correct each contradiction in the document, or flag it there explicitly. These documents go stale because nobody edits them, so no PR-triggered check can catch it — this step is the only control. Instance: on 2026-07-31 `product/open-preview-blockers-20260815.md` still showed security blocker #4491 with mitigation "due this week" six days after PR #4497 (merged 2026-07-25) shipped the interim mitigation that removed #4491 from the Aug 11 gate — telling the PO the Aug 11 launch gate was blocked when it was not. Note the direction of the correction: #4491 itself remains OPEN pending the durable fix, so the document was wrong about the gate, not about the issue's state. Same drift produced the stale registry-submission exception (iteration 98) and a metric assumption that outlived its replacement by six days.
13
+ 7. Confirm every GitHub issue and PR referenced in a team-owned tracking document was reconciled against its real state with `gh issue view` / `gh pr view` before that document is cited in a product-owner-facing decision or status report. Correct each contradiction in the document, or flag it there explicitly. These documents go stale without anyone editing them — the issues and PRs they cite change state elsewhere — so no PR-triggered check sees a diff to fire on; this step fires at iteration close instead. Scope limit: this step only triggers when an agent cites such a document in a product-owner-facing decision or status report. A stale document the PO opens and reads directly is not covered — nothing in this checklist causes anyone to reconcile it. Instance: on 2026-07-31 `product/open-preview-blockers-20260815.md` still showed security blocker #4491 with mitigation "due this week" six days after PR #4497 (merged 2026-07-25) shipped the interim mitigation that removed #4491 from the Aug 11 gate — telling the PO the Aug 11 launch gate was blocked when it was not. Note the direction of the correction: #4491 itself remains OPEN pending the durable fix, so the document was wrong about the gate, not about the issue's state. Same drift produced the stale registry-submission exception (iteration 98) and a metric assumption that outlived its replacement by six days.
14
14
  8. List any unresolved risks before declaring the iteration complete.
15
15
 
16
16
  ## Required Output
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memnexus-ai/mx-agent-cli",
3
- "version": "0.1.254",
3
+ "version": "0.1.256",
4
4
  "description": "CLI for creating and managing AI agent teams",
5
5
  "type": "module",
6
6
  "bin": {