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

未关闭 适合新手
#133 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, sqlite

调研方向

从 src/sqlite_graph_memory/brain_ask.py、src/sqlite_graph_memory/index_notes.py 和 src/sqlite_graph_memory/doctor.py 中的 main() 开始;阅读现有的解析器模式和 tests/test_version_flag.py。为帮助信息、未知标志、分隔符 -- 和 sgm-index --version 添加测试,并确保显示帮助信息时不会加载模型或操作文件。先运行针对性测试,再运行 python -m pytest -q;所有列出的命令行为均通过后即完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
9
派生
6
平均合并
13 小时 8 分钟
30 天内合并 PR
40

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tonydzi/sqlite-graph-memory 的其他 Issue

查看 tonydzi/sqlite-graph-memory 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。