@miller-tech/uap 1.187.3 → 1.187.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miller-tech/uap",
3
- "version": "1.187.3",
3
+ "version": "1.187.4",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,40 +27,77 @@ PM_BUILTINS = {
27
27
  PMS = ("npm", "pnpm", "yarn")
28
28
 
29
29
 
30
+ # A command is a sequence of STATEMENTS; each one invokes its own binary.
31
+ _STATEMENT_SPLIT_RE = re.compile(r"&&|\|\||[;|&\n]")
32
+
33
+
34
+ def _leading_binary(statement: str) -> tuple[str, list[str]] | None:
35
+ """The binary a statement invokes, plus its tokens — or None.
36
+
37
+ Skips env assignments (`FOO=bar cmd`) and shell grouping, then reads the
38
+ FIRST real word. That word is what the shell executes; a wrapped CLI
39
+ appearing later is an argument, not an invocation.
40
+ """
41
+ tokens = statement.replace("(", " ").replace("{", " ").split()
42
+ idx = 0
43
+ while idx < len(tokens) and "=" in tokens[idx].split("/")[0]:
44
+ idx += 1 # env assignment prefix
45
+ if idx >= len(tokens):
46
+ return None
47
+ return tokens[idx].split("/")[-1], tokens[idx:]
48
+
49
+
30
50
  def main() -> None:
31
51
  op, args = parse_cli()
32
52
  cmd = (args.get("command") or args.get("cmd") or "").strip()
33
53
  if not cmd or op.lower() != "bash":
34
54
  emit(True, "not a Bash command")
35
55
 
36
- first = cmd.split(maxsplit=1)[0].lstrip("(").lstrip("{")
37
- if first == "rtk" and RTK_META.search(cmd):
38
- emit(True, "rtk meta command")
39
- if ALREADY_WRAPPED.match(cmd):
40
- emit(True, "already wrapped")
41
-
42
- # Inspect tokens (ignore env assignments like FOO=bar cmd)
43
- tokens = [t for t in cmd.split() if "=" not in t.split("/")[0]]
44
- for tok in tokens[:3]:
45
- bin_name = tok.split("/")[-1]
46
- if bin_name in WRAPPED:
47
- wrapper = "rtk"
48
- if bin_name in PMS:
49
- sub = ""
50
- for nxt in tokens[tokens.index(tok) + 1:]:
51
- if not nxt.startswith("-"):
52
- sub = nxt.split("/")[-1]
53
- break
54
- if sub in PM_BUILTINS:
55
- wrapper = "rtk proxy"
56
- emit(
57
- False,
58
- f"rtk-wrap: '{bin_name}' must be invoked via rtk. "
59
- f"Use: {wrapper} {cmd}",
60
- bin=bin_name,
61
- )
62
-
63
- emit(True, "no wrapped CLI in command")
56
+ # Evaluate each statement on its own.
57
+ #
58
+ # Whole-command matching got this wrong in BOTH directions. It only accepted
59
+ # `rtk` at the very start, so `cd /srv/app && rtk git log` — already wrapped —
60
+ # was refused, with a suggestion that prefixed rtk to the entire line and
61
+ # produced nonsense like `rtk cd /srv/app; git log`. And it scanned only the
62
+ # first three tokens, so `cd /srv/app && git log` slipped through entirely:
63
+ # `git` sat at index 3. That is a bypass, not just noise — any bare invocation
64
+ # could be hidden behind a `cd`. Reading the leading binary of each statement
65
+ # fixes both, because that is what the shell actually runs.
66
+ for raw in _STATEMENT_SPLIT_RE.split(cmd):
67
+ statement = raw.strip()
68
+ if not statement:
69
+ continue
70
+ found = _leading_binary(statement)
71
+ if not found:
72
+ continue
73
+ bin_name, tokens = found
74
+
75
+ # A statement led by `rtk` (or anything else outside WRAPPED) is fine:
76
+ # in `rtk git log` the leading binary is rtk and `git` is its argument.
77
+ # No separate rtk check is needed - rtk is simply not a wrapped CLI.
78
+ # Mutation testing flagged the earlier explicit check as equivalent,
79
+ # i.e. dead.
80
+ if bin_name not in WRAPPED:
81
+ continue
82
+
83
+ wrapper = "rtk"
84
+ if bin_name in PMS:
85
+ sub = ""
86
+ for nxt in tokens[1:]:
87
+ if not nxt.startswith("-"):
88
+ sub = nxt.split("/")[-1]
89
+ break
90
+ if sub in PM_BUILTINS:
91
+ wrapper = "rtk proxy"
92
+ # Suggest fixing THIS statement, not the whole line.
93
+ emit(
94
+ False,
95
+ f"rtk-wrap: '{bin_name}' must be invoked via rtk. "
96
+ f"Use: {wrapper} {statement}",
97
+ bin=bin_name,
98
+ )
99
+
100
+ emit(True, "no unwrapped CLI in any statement")
64
101
 
65
102
 
66
103
  if __name__ == "__main__":