Skip to content

Answer --help so agents can open files in Omawrite - #35

Open
jankeesvw wants to merge 1 commit into
omacom:masterfrom
jankeesvw:answer-help-in-the-terminal
Open

Answer --help so agents can open files in Omawrite#35
jankeesvw wants to merge 1 commit into
omacom:masterfrom
jankeesvw:answer-help-in-the-terminal

Conversation

@jankeesvw

Copy link
Copy Markdown

Ask a coding agent to open a Markdown file in Omawrite and the first thing it does is check how the command works. That check never comes back.

What an agent does

Four agents, same instruction ("open <file> in Omawrite"), no other guidance. Three of the four reached for --help before anything else. Taken from ps, not from what they reported:

22:10:29  omawrite --help
22:10:29  omawrite --help
22:10:30  omawrite --help
22:10:45  omawrite .../d.md      (15s later)
22:11:22  omawrite .../b.md      (52s later)
22:11:26  omawrite .../e.md      (56s later)
22:11:37  omawrite .../c.md      (67s later)

None of them got an answer:

$ omawrite --help 2>&1; echo "EXIT:$?"
EXIT:0

Omawrite has no --help (or prints nothing to stdout/stderr).

So they went looking elsewhere. Between them, before any of them opened the file, they ran:

$ cat /usr/bin/omawrite | head -50          # 44KB of ELF
$ strings /usr/bin/omawrite | grep -iE "usage|open|error|help"
$ find / -iname "*omawrite*" ...            # whole filesystem, 3-5s
$ cat /usr/share/applications/omawrite.desktop

They all got there in the end, 15 to 67 seconds later, by guessing that a bare file argument would work. Each --help also put a window on screen showing Could not open --help. in the footer.

Why

main.cpp passes argv[1] straight to Backend::open() as a file name, so --help is read as a file that cannot exist. Nothing reaches the terminal, and the process stays up until the window is closed.

Built from master (8f98892) on Arch with Qt 6.11.2, run with QT_QPA_PLATFORM=offscreen:

$ omawrite --help
(no output, killed after 15s, never exits on its own)

$ omawrite -h
(no output, killed after 15s, never exits on its own)

$ omawrite --nope
(no output, killed after 15s, never exits on its own)

After

Same machine, same Qt, this branch:

$ omawrite --help
Omawrite is a dead-simple Markdown writing app.

Usage:
  omawrite [FILE]

Opens the Omawrite window. FILE is the Markdown file to open; without
one, Omawrite starts on an empty document, or on the draft recovered
from the last session.

Options:
  -h, --help    Show this message and exit

Omawrite is a graphical app: it needs a desktop session, and it keeps
running until the window is closed. Scripts and agents that only want
a file on screen should background it:

  omawrite draft.md &

Everything else is a keyboard shortcut. Ctrl+? lists them in the app,
and https://github.com/omacom-io/omawrite#shortcuts has the same list.

(exit 0, 17ms)

$ omawrite --nope
omawrite: unrecognized option '--nope'

(usage follows on stderr, exit 1, 16ms)

omawrite FILE is unchanged: it opens the window and stays up as before.

What changed

Arguments are parsed in a small src/cli.cpp before QApplication is constructed, so the usage prints even without a desktop session to open a window in. Anything starting with a dash that isn't -h/--help gets an error plus the usage on stderr and exit 1, instead of being treated as a file name.

There's a test in tests/tst_omawrite.cpp; bin/test passes 13/13.

I left --version out because there is no version constant in the source yet. Happy to add one if you want it.

Ask a coding agent to open a Markdown file in Omawrite and the first thing
it runs is `omawrite --help`, to work out how. Today that opens a window
that says "Could not open --help.", prints nothing to the terminal, and
keeps running until the window is closed. So the agent hangs on a process
that never exits, and never learns that Omawrite takes a file.

Parse the arguments before QApplication starts, so the usage prints even
without a desktop session to open a window in, and reject unknown options
instead of treating them as file names. The usage also says the process
stays up until the window is closed, which is the other half of what a
script needs to know.
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.

1 participant