Skip to content

[OMEGA-174] Multi-line command argument parsing of MeTTaClaw#223

Open
patham9 wants to merge 3 commits into
mainfrom
MultilineCommand
Open

[OMEGA-174] Multi-line command argument parsing of MeTTaClaw#223
patham9 wants to merge 3 commits into
mainfrom
MultilineCommand

Conversation

@patham9

@patham9 patham9 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Multi-line argument was restricted to send command, and parsing seemed more complex than necessary.

How Has This Been Tested?

Tested with MeTTaClaw live Max Botnick instance.

Checklist

  • The code generated by LLM is reviewed by the PR creator
  • Self-review completed
  • Test scenarios above are passed with the version of the code from PR

@alyona-snet alyona-snet changed the title Multi-line command argument parsing of MeTTaClaw [OMEGA-210] Multi-line command argument parsing of MeTTaClaw Jul 1, 2026
@patham9

patham9 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

The autotest with ((command fails, this double parenthesis case occurs? If so it can be extended to handle it.

@vsbogd

vsbogd commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

The autotest with ((command fails, this double parenthesis case occurs? If so it can be extended to handle it.

The reason test fails is additional quote inside the string:

E       assert '((send "\\"P...arf planet"))' == '((send "Plai...arf planet"))'
E         
E         - ((send "Plain text version:\n**Mars** - red planet\nNote: Pluto is a dwarf planet"))
E         + ((send "\"Plain text version:\"\n**Mars** - red planet\nNote: Pluto is a dwarf planet"))
E         ?        ++                    ++

My opinion the behavior of your code @patham9 is correct in this sense. I would suggest fixing the test assert condition:

-    assert balance_parentheses('send "Plain text version:"\n**Mars** - red planet\nNote: Pluto is a dwarf planet') == '((send "Plain text version:\\n**Mars** - red planet\\nNote: Pluto is a dwarf planet"))'
+    assert balance_parentheses('send "Plain text version:"\n**Mars** - red planet\nNote: Pluto is a dwarf planet') == '((send "\\\"Plain text version:\\\"\\n**Mars** - red planet\\nNote: Pluto is a dwarf planet"))'

@vsbogd vsbogd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this change improves the previous implementation. I would also ask to add the unit tests which checks that multi-line parsing works for the commands other than send.

Comment thread src/helper.py
Comment on lines 62 to 66
def _strip_outer_parens(line):
if line.startswith("(") and line.endswith(")"):
return line[1:-1].strip()
return line

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not used and could be removed:

Suggested change
def _strip_outer_parens(line):
if line.startswith("(") and line.endswith(")"):
return line[1:-1].strip()
return line

Comment thread src/helper.py
Comment on lines +87 to +88
if cur:
cur.append(raw)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why empty string is added into the current block? No tests are broken if it is removed:

Suggested change
if cur:
cur.append(raw)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it executes commands like write-file, the additional newlines can matter. This just preserves this, as else it would truncate them.

Comment thread src/helper.py
def balance_parentheses(s):
s = s.replace("_quote_", '"').replace("_newline_", "\n")
sexprs = []
special_two_arg_cmds = {"write-file", "append-file"}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deserves to be a global constant like LLM_COMMANDS.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Maybe TWO_ARG_COMMANDS

Comment thread src/helper.py
Comment on lines 107 to 110
if line.startswith("(-"):
line = "(pin -" + line[2:]
elif line.startswith("-"):
line = "pin " + line

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patham9 why this replacement is needed? No test is broken if removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore probably, was more an issue with Minimax M2.7 that it used listings without command.

Comment thread src/helper.py
content = split_rest[1].strip() if len(split_rest) > 1 else ""
if content:
if content.startswith('"') and content.endswith('"'):
if content.startswith('"') and content.endswith('"') and "\n" not in content:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the code of quote_arg to include this condition. I.e. make quote_args adding quotes only if they are absent. If so it would significantly simplify the code by removing this condition from balance_parenthesis function. For example this condition will turn to:

sexprs.append(f"({cmd} {filename} {quote_arg(content)})")

the same for if rest block below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this, but it should be fine too.

@vsbogd vsbogd changed the title [OMEGA-210] Multi-line command argument parsing of MeTTaClaw [OMEGA-174] Multi-line command argument parsing of MeTTaClaw Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants