chore: require workspace

This commit is contained in:
ajspig 2026-04-13 16:20:49 -04:00
parent 7ec5593ea6
commit 2599784a6a
4 changed files with 28 additions and 9 deletions

View File

@ -38,11 +38,13 @@ def list_messages(
sess = client.session(sid)
try:
msgs = list(sess.messages())
# SDK returns most-recent-first. Default case (newest N) only needs
# the first page. --reverse (oldest N) still walks all pages until
# the SDK accepts order=asc on session.messages().
if not reverse:
msgs = msgs[-last:]
msgs = sess.messages().items[:last]
else:
msgs = msgs[:last]
msgs = list(sess.messages())[-last:]
# Detect duplicate content
content_hashes: dict[str, list[str]] = {}

View File

@ -125,11 +125,13 @@ def messages(
sess = client.session(sid)
try:
msgs = list(sess.messages())
# SDK returns most-recent-first. Default case (newest N) only needs
# the first page. --reverse (oldest N) still walks all pages until
# the SDK accepts order=asc on session.messages().
if not reverse:
msgs = msgs[-last:]
msgs = sess.messages().items[:last]
else:
msgs = msgs[:last]
msgs = list(sess.messages())[-last:]
items = [
{

View File

@ -53,7 +53,7 @@ def list_workspaces(
from honcho_cli.main import get_client
handle_cmd_flags(json_output=json_output)
client, config = get_client()
client, config = get_client(require_workspace=False)
try:
workspaces = list(client.workspaces())

View File

@ -89,13 +89,28 @@ def get_resolved_config():
return config
def get_client():
"""Create a Honcho client from resolved config."""
def get_client(*, require_workspace: bool = True):
"""Create a Honcho client from resolved config.
By default, refuses to build a client when no workspace is scoped — the
SDK's get-or-create semantics would otherwise silently operate on an empty
workspace. Commands that legitimately run without a workspace (e.g.
``workspace list``) pass ``require_workspace=False``.
"""
import typer
from honcho import Honcho
from honcho_cli.config import get_client_kwargs
from honcho_cli.output import print_error
config = get_resolved_config()
if require_workspace and not config.workspace_id:
print_error(
"NO_WORKSPACE",
"No workspace scoped. Pass --workspace/-w or set HONCHO_WORKSPACE_ID.",
)
raise typer.Exit(1)
return Honcho(**get_client_kwargs(config)), config