mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
fix(kanban): restore HERMES_KANBAN_BOARD after scoped slash override
This commit is contained in:
parent
2b3bf17dfa
commit
641e40c4bd
2 changed files with 30 additions and 1 deletions
|
|
@ -652,6 +652,16 @@ def kanban_command(args: argparse.Namespace) -> int:
|
||||||
# keeps the patch small and inherits the exact same resolution the
|
# keeps the patch small and inherits the exact same resolution the
|
||||||
# dispatcher uses for workers — consistency is a feature here.
|
# dispatcher uses for workers — consistency is a feature here.
|
||||||
board_override = getattr(args, "board", None)
|
board_override = getattr(args, "board", None)
|
||||||
|
prev_board_env = os.environ.get("HERMES_KANBAN_BOARD")
|
||||||
|
restore_board_env = False
|
||||||
|
|
||||||
|
def _restore_board_env() -> None:
|
||||||
|
if not restore_board_env:
|
||||||
|
return
|
||||||
|
if prev_board_env is None:
|
||||||
|
os.environ.pop("HERMES_KANBAN_BOARD", None)
|
||||||
|
else:
|
||||||
|
os.environ["HERMES_KANBAN_BOARD"] = prev_board_env
|
||||||
if board_override:
|
if board_override:
|
||||||
try:
|
try:
|
||||||
normed = kb._normalize_board_slug(board_override)
|
normed = kb._normalize_board_slug(board_override)
|
||||||
|
|
@ -671,12 +681,16 @@ def kanban_command(args: argparse.Namespace) -> int:
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
os.environ["HERMES_KANBAN_BOARD"] = normed
|
os.environ["HERMES_KANBAN_BOARD"] = normed
|
||||||
|
restore_board_env = True
|
||||||
|
|
||||||
# Boards management doesn't touch the DB at all — dispatch early so
|
# Boards management doesn't touch the DB at all — dispatch early so
|
||||||
# fresh installs that haven't initialized any DB can still use
|
# fresh installs that haven't initialized any DB can still use
|
||||||
# `hermes kanban boards create …`.
|
# `hermes kanban boards create …`.
|
||||||
if action == "boards":
|
if action == "boards":
|
||||||
return _dispatch_boards(args)
|
try:
|
||||||
|
return _dispatch_boards(args)
|
||||||
|
finally:
|
||||||
|
_restore_board_env()
|
||||||
|
|
||||||
# Auto-initialize the DB before dispatching any subcommand. init_db
|
# Auto-initialize the DB before dispatching any subcommand. init_db
|
||||||
# is idempotent, so running it every invocation is cheap (one
|
# is idempotent, so running it every invocation is cheap (one
|
||||||
|
|
@ -689,6 +703,7 @@ def kanban_command(args: argparse.Namespace) -> int:
|
||||||
kb.init_db()
|
kb.init_db()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f"kanban: could not initialize database: {exc}", file=sys.stderr)
|
print(f"kanban: could not initialize database: {exc}", file=sys.stderr)
|
||||||
|
_restore_board_env()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
handlers = {
|
handlers = {
|
||||||
|
|
@ -730,12 +745,16 @@ def kanban_command(args: argparse.Namespace) -> int:
|
||||||
handler = handlers.get(action)
|
handler = handlers.get(action)
|
||||||
if not handler:
|
if not handler:
|
||||||
print(f"kanban: unknown action {action!r}", file=sys.stderr)
|
print(f"kanban: unknown action {action!r}", file=sys.stderr)
|
||||||
|
_restore_board_env()
|
||||||
return 2
|
return 2
|
||||||
try:
|
try:
|
||||||
return int(handler(args) or 0)
|
return int(handler(args) or 0)
|
||||||
except (ValueError, RuntimeError) as exc:
|
except (ValueError, RuntimeError) as exc:
|
||||||
print(f"kanban: {exc}", file=sys.stderr)
|
print(f"kanban: {exc}", file=sys.stderr)
|
||||||
|
_restore_board_env()
|
||||||
return 1
|
return 1
|
||||||
|
finally:
|
||||||
|
_restore_board_env()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -392,3 +392,13 @@ def test_run_slash_missing_required_arg_friendly_error(kanban_home):
|
||||||
out = kc.run_slash("show")
|
out = kc.run_slash("show")
|
||||||
assert "/kanban show" in out
|
assert "/kanban show" in out
|
||||||
assert "task_id" in out
|
assert "task_id" in out
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_slash_board_override_restores_prior_env(kanban_home, monkeypatch):
|
||||||
|
kb.create_board("alpha")
|
||||||
|
kb.create_board("beta")
|
||||||
|
monkeypatch.setenv("HERMES_KANBAN_BOARD", "beta")
|
||||||
|
|
||||||
|
kc.run_slash("--board alpha list")
|
||||||
|
|
||||||
|
assert os.environ.get("HERMES_KANBAN_BOARD") == "beta"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue