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

Đang mở Phù hợp với người mới
#133 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sqlite
Lĩnh vực
cli, developer-experience

Hướng nghiên cứu

Bắt đầu với main() trong src/sqlite_graph_memory/brain_ask.py, src/sqlite_graph_memory/index_notes.py và src/sqlite_graph_memory/doctor.py; đọc các mẫu parser hiện có và tests/test_version_flag.py. Thêm kiểm thử cho phần trợ giúp, các cờ không xác định, dấu phân cách -- và sgm-index --version, đồng thời đảm bảo phần trợ giúp không tải mô hình hoặc thao tác với tệp. Chạy các kiểm thử tập trung, rồi chạy python -m pytest -q; hoàn tất khi tất cả hành vi lệnh được liệt kê đều đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
9
Fork
6
Merge trung bình
13 giờ 8 phút
Pull request đã merge (30 ngày)
40

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tonydzi/sqlite-graph-memory

Tất cả issue của tonydzi/sqlite-graph-memory

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.