sgm-index --help is an error, and sgm-ask embeds --help or a mistyped flag as the query

Aperta Adatta ai principianti
#133 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, sqlite

Direzione di ricerca

Inizia da main() in src/sqlite_graph_memory/brain_ask.py, src/sqlite_graph_memory/index_notes.py e src/sqlite_graph_memory/doctor.py; leggi i pattern esistenti dei parser e tests/test_version_flag.py. Aggiungi test per l’aiuto, i flag sconosciuti, il separatore -- e sgm-index --version, assicurandoti che l’aiuto non carichi un modello né tocchi file. Esegui i test mirati, poi python -m pytest -q; il lavoro è terminato quando tutti i comportamenti dei comandi elencati passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug good first issue

What happens

The two commands a new user runs first have no working --help, and sgm-ask accepts any unknown flag as part of the question.

On a clone of master (0.3.9, Windows 11, Python 3.12, [lite] backend, index built from bench/vault):

$ sgm-index --help
usage: sgm-index [--full] [notes_dir]
sgm-index: error: unrecognized arguments: --help
$ echo $?
2

$ sgm-index --version
usage: sgm-index [--full] [notes_dir]
sgm-index: error: unrecognized arguments: --version

$ sgm-ask --help
12 hits (scope=all) -> _brain_answer.txt
$ head -2 _brain_answer.txt
QUERY: --help
(scope=all; e5 60 files -> dense; 204 chunks)

$ sgm-ask --grahp "ouzel"        # typo of --graph
12 hits (scope=all) -> _brain_answer.txt
$ head -1 _brain_answer.txt
QUERY: --grahp ouzel

Causes:

  • src/sqlite_graph_memory/index_notes.py:258 builds the parser with argparse.ArgumentParser(add_help=False), so --help is rejected. Running sgm-index with no arguments does print the module docstring.
  • src/sqlite_graph_memory/brain_ask.py:547-548 keeps a fixed set of known flags and joins everything else into the query. --help loads the model, runs a recall for the text --help, overwrites _brain_answer.txt and exits 0. A mistyped flag silently turns the mode off and changes the query.

sgm-stats and sgm-turnstate-show already use a normal argparse parser, and #75 added --version to sgm-stats and sgm-ask. sgm-doctor --help ignores the flag and just runs the checks.

Why it matters

--help is the first thing people type. Today it is an error for one command and a slow, misleading recall for the other. The typo case is worse for evaluation work: sgm-ask --grahp ... looks like a successful graph run but is a vector run on a different query.

Suggested approach

  • sgm-index: drop add_help=False, pass the module docstring as the description (with formatter_class=argparse.RawDescriptionHelpFormatter), add --version in the same style as #75.
  • sgm-ask: handle -h / --help first by printing the module docstring and exiting 0. For any other argument that starts with -- and is not a known flag, print unknown option: <arg> to stderr and exit 2. Support a literal -- separator so a question that really starts with dashes can still be asked (today sgm-ask -- "--help" runs a recall for the text -- --help).
  • sgm-doctor: accept -h / --help and print a short usage text.
  • Keep the manual parsing in brain_ask.py if a full argparse rewrite feels too large; the checks above are enough. Mind the --pool option, which _parse_pool already strips before the flag set is applied.

Done when

  • sgm-index --help, sgm-ask --help and sgm-doctor --help exit 0, print usage, do not load a model and do not write _brain_answer.txt or touch the index.
  • sgm-ask --grahp "x" exits 2 with a message that names the unknown option.
  • sgm-ask -- "--help" runs a recall for the text --help.
  • sgm-index --version prints sgm-index <version>.
  • New tests next to tests/test_version_flag.py cover these cases without a model or an index, and fail on current master.
  • python -m pytest -q shows no new failures.

Where to start

  • src/sqlite_graph_memory/brain_ask.py: main() from line 538, _parse_pool at line 495 for the existing style of manual flag parsing
  • src/sqlite_graph_memory/index_notes.py: main() at line 257
  • src/sqlite_graph_memory/doctor.py: main() at line 185
  • tests/test_version_flag.py as a template

New here? Comment that you are taking it and ask anything in this thread; small PRs are reviewed within a day.

Lingua principale
Python
Stelle
9
Fork
6
Merge medio
13h 8m
PR unite (30g)
40

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tonydzi/sqlite-graph-memory

Tutte le issue di tonydzi/sqlite-graph-memory

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.