Skip to content

fix: add --version flag, use --yes in agent init instructions, document init prerequisite for mine#559

Open
adiKhan12 wants to merge 2 commits intoMemPalace:developfrom
adiKhan12:fix/agent-instructions
Open

fix: add --version flag, use --yes in agent init instructions, document init prerequisite for mine#559
adiKhan12 wants to merge 2 commits intoMemPalace:developfrom
adiKhan12:fix/agent-instructions

Conversation

@adiKhan12
Copy link
Copy Markdown

What does this PR do?

Fixes #534. Three issues that break agent-driven use of MemPalace:

1. mempalace --version crashes (exit 2)

SKILL.md prerequisites tell agents to run mempalace --version, but the flag didn't exist:

$ mempalace --version
error: unrecognized arguments: --version

Fix: Added --version to the CLI argparser using existing version.py.

$ mempalace --version
mempalace 3.1.0

2. mempalace init without --yes causes EOFError in agent context

When entities are detected, confirm_entities() calls input() which crashes agents (no stdin):

File "entity_detector.py", line 787, in confirm_entities
    if choice == "add" or input("\n  Add any missing? [y/N]: ").strip().lower() == "y":
EOFError: EOF when reading a line

Fix: Updated instructions/init.md Step 5 to use mempalace init --yes <dir>. The --yes flag already existed (#8) but the agent instructions didn't use it.

3. mempalace mine fails with no guidance when init hasn't run

$ mempalace mine /path/to/dir
ERROR: No mempalace.yaml found in /path/to/dir
Run: mempalace init /path/to/dir

Agents following instructions/mine.md hit this with no context.

Fix: Added Step 0 to instructions/mine.md documenting the init prerequisite with the exact error message.

How to test

python -m pytest tests/test_cli.py tests/test_instructions_cli.py -v

New tests:

  • test_main_version_flag — verifies --version prints version and exits 0
  • test_cmd_init_yes_skips_interactive_prompts — verifies yes=True is passed through to confirm_entities
  • test_init_instructions_use_yes_flag — verifies init.md contains mempalace init --yes
  • test_mine_instructions_mention_init_prerequisite — verifies mine.md mentions mempalace init and mempalace.yaml

Checklist

  • Tests pass (python -m pytest tests/ -v) — 538 passing
  • No hardcoded paths
  • Linter passes (ruff check .)

…t prerequisite for mine

Fixes MemPalace#534. Three issues that break agent-driven use of MemPalace:

1. `mempalace --version` did not exist — agents following SKILL.md
   prerequisites hit exit code 2. Added --version flag to the CLI
   argparser using the existing version.py.

2. `mempalace instructions init` Step 5 used `mempalace init <dir>`
   without --yes — agents hit EOFError when entity detection triggers
   interactive prompts (confirm_entities calls input() on closed stdin).
   Updated to `mempalace init --yes <dir>`.

3. `mempalace instructions mine` did not mention that `mempalace init`
   must run first — agents hit "No mempalace.yaml found" with no
   guidance. Added Step 0 documenting the prerequisite.
@adiKhan12 adiKhan12 force-pushed the fix/agent-instructions branch from 405f388 to b6a1683 Compare April 10, 2026 18:10
@web3guru888
Copy link
Copy Markdown

This directly addresses the three agent-init failure modes I diagnosed in #534 — all three fixes are correct and the test coverage is solid.

Fix 1 (--version): parser.add_argument("--version", action="version", version=f"mempalace {__version__}") is exactly right. Using argparse's built-in action="version" is the canonical approach — it exits 0 (not 2), which is what SKILL.md prerequisite checks need. The version.py import is already in the file. Clean.

Fix 2 (--yes in instructions): The EOFError on input() is a silent killer for headless agents. Adding --yes to instructions/init.md is the right fix over the alternatives (the --yes flag already existed via #8 — this was a docs gap, not a code gap). The added prose explaining why the flag is required is useful; most instruction files don't explain the rationale and agents cargo-cult the command without understanding it.

Fix 3 (mine prerequisite): Adding Step 0 to mine.md is the right UX. The "auto-init when yaml is missing" alternative I mentioned in #534 has a real footgun: agents mining a subdirectory would silently create a palace in the wrong place. Explicit prerequisite documentation is safer.

Tests: All four new tests are behavioral, not structural — they verify the flag works and the instructions contain the right text. The test_cmd_init_yes_skips_interactive_prompts approach of asserting confirm_entities receives yes=True is exactly right (verifies the plumbing, not the argparse config).

One small observation: test_mine_instructions_mention_init_prerequisite checks for "mempalace init" and "mempalace.yaml" in the content. It would also be worth asserting "mempalace init --yes" specifically (so a future edit that removes --yes from mine.md would fail). Not a blocker, just a tighter assertion.

LGTM. We hit variant 2 of this in our own setup early on — had to trace the EOFError back to the --yes gap manually. Having it documented in the skill instructions will save everyone that debugging cycle.


MemPalace-AGI integration — 208 discoveries, 120 tests | dashboard

@adiKhan12
Copy link
Copy Markdown
Author

Thanks @web3guru888 — good catch on the assertion. Just pushed a follow-up commit tightening test_mine_instructions_mention_init_prerequisite to assert "mempalace init --yes" specifically instead of just "mempalace init". That way a future edit dropping --yes from mine.md would fail the test.

@jphein
Copy link
Copy Markdown
Collaborator

jphein commented Apr 10, 2026

Note: #562 also fixes the SKILL.md (mempalace status instead of --version) and the init instructions (--yes flag). We skipped adding --version to the CLI since mempalace status already serves as the health check.

@adiKhan12
Copy link
Copy Markdown
Author

Thanks for flagging the overlap with #562.

Looking at the diff, there are a couple of differences in approach:

  1. --version: feat: batch writes, concurrent mining, MCP tools, hooks, export, search improvements #562 works around the missing flag by changing SKILL.md to use mempalace status. Our PR adds the actual --version flag to the CLI — --version is a standard convention that users and tools expect (pip --version, git --version, etc.), so having it exist is independently useful beyond just the SKILL.md prerequisite check.

  2. init --yes explanation: feat: batch writes, concurrent mining, MCP tools, hooks, export, search improvements #562 changes the command but doesn't explain why --yes is needed. Our PR adds context about the EOFError so future editors of init.md understand the constraint and don't accidentally remove it.

  3. mine prerequisite: feat: batch writes, concurrent mining, MCP tools, hooks, export, search improvements #562 doesn't address the missing init prerequisite in mine.md — agents following mine instructions still hit ERROR: No mempalace.yaml found with no guidance.

Happy to coordinate — if #562 lands first, I can rebase and keep just the parts that don't overlap (--version flag, mine.md Step 0, tests).

@web3guru888
Copy link
Copy Markdown

@adiKhan12 — the differentiation is well-argued. The three differences are real:

On --version: Agreed that adding the actual flag is independently correct. mempalace status works as a health check but --version is a separate expectation — most tooling (shell scripts, CI, dependency manifests) keys off --version not on status. The two serve different purposes. The #562 workaround solves the immediate SKILL.md problem; your approach also closes the UX gap for anyone else who reaches for --version instinctively.

On the mine Step 0: This is the one #562 is missing that matters most in agent contexts. An agent that follows mine.md without having run init will get a silent failure or cryptic error — the prerequisite note is necessary for robust agent automation, and it's not something #562 addressed.

On rebasing: The rebase-and-keep approach you described is the right path. If #562 merges first, a rebased version that trims to just (1) --version flag + its test and (2) the mine.md Step 0 addition would be a clean, non-conflicting follow-on. The init --yes context might also be worth keeping since neither PR currently has that explanation, depending on which init.md changes survive.

The tightened test assertion (asserting mempalace init --yes rather than just mempalace init) is exactly the right call — that's the kind of regression guard that pays off six months from now.

jphein added a commit to jphein/mempalace that referenced this pull request Apr 11, 2026
@jphein
Copy link
Copy Markdown
Collaborator

jphein commented Apr 11, 2026

Nice addition! We incorporated this --version flag into our fork (jphein/mempalace@fe5cd56) and included it in PR #562 which bundles several community fixes. Thanks @adiKhan12!

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

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

Review: fix: add --version flag, use --yes in agent init instructions, document init prerequisite for mine

Three distinct fixes bundled together, all targeting the same pain: MemPalace failing silently (or crashingly) when driven by an agent. Small PR, high practical value.

What's done well

--version uses action="version" correctly. The argparse action="version" idiom prints the version string and exits 0 — exactly the right mechanism. It's wired to __version__ from version.py, not a hardcoded string, so it'll stay accurate as the version is bumped. The version string format mempalace {__version__} is conventional and machine-parseable. No complaints here.

--yes documentation fills a real gap. The --yes flag has existed since #8 but the agent instructions never told agents to use it. Agents hitting EOFError on input() get a confusing stack trace with no guidance. The fix is exactly right: update the instructions, add a test that verifies init --yes skips input(). The "Without it, the command will crash with EOFError when stdin is not a terminal" note in init.md is particularly good — it explains why, not just what.

Step 0 in mine.md is the right level of specificity. It gives the exact error message agents will see (ERROR: No mempalace.yaml found in <dir>), the exact fix, and even the check condition (if a mempalace.yaml file exists). An agent following this document won't need to ask for help.

Tests cover the content of the markdown files. test_init_instructions_use_yes_flag and test_mine_instructions_mention_init_prerequisite assert on the actual file content, not just code behavior. This prevents someone from "fixing" the code while silently breaking the agent instructions again.

Issues found

The test_main_version_flag test is referenced in the PR description but not visible in the diff. The PR lists four new tests; I see test_cmd_init_yes_skips_interactive_prompts, test_init_instructions_use_yes_flag, and test_mine_instructions_mention_init_prerequisite in the diff. The test_main_version_flag test that verifies --version prints the version and exits 0 should be in test_cli.py — worth confirming it's present (may be outside the visible diff window if the file is large).

init.md Step 5 says "The --yes flag is required in agent/non-interactive contexts." Technically it's not required — mempalace init without --yes works fine in an interactive terminal. The word "required" could confuse a human user reading the docs. Something like "Use --yes to skip interactive prompts in agent/non-interactive contexts" is more accurate.

No SKILL.md update. The PR description mentions SKILL.md prerequisites tell agents to run mempalace --version, implying SKILL.md documents the --version flag as a prerequisite check. If SKILL.md exists and is already correct, no issue. If it still documents the broken invocation (or lacks --version entirely), it should be updated in this PR.

mine.md Step 0 uses a bash code block with mempalace init --yes <dir>. This is good, but the step says "Check if a mempalace.yaml file exists in the target directory" without specifying how an agent should check (e.g., test -f <dir>/mempalace.yaml). A concrete shell command would make this step machine-executable without ambiguity.

Suggestions

  1. Confirm test_main_version_flag is present (or add it if missing from the batch).
  2. Change "required" to "recommended" or "necessary" in init.md to avoid confusing interactive users.
  3. Add a test -f <dir>/mempalace.yaml example to mine.md Step 0 for fully unambiguous agent instructions.
  4. Verify SKILL.md is consistent with these changes.

Overall verdict

Approve. The three fixes are all correct: --version is wired properly to __version__, the --yes documentation fills a genuine gap that was causing real agent crashes, and the mine.md prerequisite note saves agents from a confusing dead-end. The issues noted are minor — none affect correctness. This is ready to merge.


Reviewed by MemPalace-AGI — autonomous research system with perfect memory

@bensig bensig changed the base branch from main to develop April 11, 2026 22:21
@bensig bensig requested a review from igorls as a code owner April 11, 2026 22:21
@igorls igorls added area/cli CLI commands area/mining File and conversation mining bug Something isn't working labels Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI commands area/mining File and conversation mining bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SKILL.md uses nonexistent mempalace --version; init instructions omit --yes so agents hit EOFError

4 participants