task: metadata: install: pip install -e .[dev]
patch: diff --git a/poetry.lock b/poetry.lock
index dd3bae9..95bb873 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -347,8 +347,8 @@ python-versions = "*"
 
 [metadata]
 lock-version = "1.1"
-python-versions = "^3.9"
-content-hash = "5453d0e820b8c811a2ae40abe1ec734f3ac2ec5e8cfb76db1953033889efdee3"
+python-versions = "^3.8"
+content-hash = "6c7bb948d0fd1b1b3c524598fd3e2fdaa6ecf189cc6ad496a1a12f606edbf119"
 
 [metadata.files]
 atomicwrites = [
diff --git a/rhi/__init__.py b/rhi/__init__.py
index 4643c6c..733b07c 100644
--- a/rhi/__init__.py
+++ b/rhi/__init__.py
@@ -1,3 +1,3 @@
 import importlib.metadata
 
-__version__ = importlib.metadata.version('rhi')
+__version__ = importlib.metadata.version("rhi")
diff --git a/rhi/commands/add.py b/rhi/commands/add.py
index 980dbb7..c07e8e3 100644
--- a/rhi/commands/add.py
+++ b/rhi/commands/add.py
@@ -22,7 +22,7 @@ class Add(Command):
                 self.command = self.cleanup_commands(args.commands, args.num)
 
     def is_history(self, line):
-        return True if re.match(r"^ +[0-9]+", line) else False
+        return True if re.match(r"^ +[0-9]+ +history", line) else False
 
     def cleanup_commands(self, inputs: io.TextIOWrapper, rownum: int = None) -> str:
         lines = [line.rstrip("\n") for line in inputs.readlines()]
@@ -30,7 +30,7 @@ class Add(Command):
         if len(lines) == 0:
             raise Exception("There's no valid lines in input")
 
-        if not self.is_history(lines[0]):
+        if not self.is_history(lines[-1]):
             return "\n".join(
                 lines
             )  # return whole input when it's not a result of history
@@ -39,11 +39,13 @@ class Add(Command):
             s = line.strip()
             return [s[: s.find(" ")].strip("* "), s[s.find(" ") + 1 :].strip()]
 
-        history_lines = [split_line(line) for line in lines]
+        history_lines = [
+            split_line(line) for line in lines if not self.is_history(line)
+        ]
         histories = {num: command for (num, command) in history_lines}
 
         if rownum is None:
-            return history_lines[max(len(lines) - 2, 0)][
+            return history_lines[-1][
                 1
             ]  # get a last line except "history" command itself
 
diff --git a/rhi/commands/version.py b/rhi/commands/version.py
index b881603..95192b6 100644
--- a/rhi/commands/version.py
+++ b/rhi/commands/version.py
@@ -1,10 +1,9 @@
-import pkg_resources
+import importlib.metadata
 
 from rhi.commands.command import Command
 
 
 class Version(Command):
-
     def invoke(self):
-        ver = pkg_resources.get_distribution('rhi').version
-        print(f'rhi-{ver}')
+        ver = importlib.metadata.version('rhi')
+        print(f"rhi-{ver}")

problem_statement: modify the way to recognize if input is a history
modify the way to recognize if input is a history.
currently, it is identified by the input follows default history format it has history number and the command like `  301   ls -lh`.
Instead of this, history command must has `history` command history at the tail of the result so use it to identify if the input came from `history` command or not.
repo: warabanshi/rhi
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/commands/test_add.py b/tests/commands/test_add.py
index 02c222c..6dd08cd 100644
--- a/tests/commands/test_add.py
+++ b/tests/commands/test_add.py
@@ -113,7 +113,7 @@ def test_cleanup_commands_empty_row(mock_add_init):
 @patch('rhi.commands.add.Add.__init__')
 def test_is_history_true(mock_add_init):
     mock_add_init.return_value = None
-    expected = True
+    expected = False
 
     add = Add()
     result = add.is_history(line1)
diff --git a/tests/test_rhi.py b/tests/test_rhi.py
index dd2f591..e9598a3 100644
--- a/tests/test_rhi.py
+++ b/tests/test_rhi.py
@@ -2,4 +2,4 @@ from rhi import __version__
 
 
 def test_version():
-    assert __version__ == '0.0.1'
+    assert __version__ == '0.0.6'