honcho-cli 0.5.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/CHANGELOG.md +10 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/PKG-INFO +4 -1
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/README.md +3 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/pyproject.toml +1 -1
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/_help.py +1 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/workspace.py +188 -3
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/common.py +48 -1
- honcho_cli-0.6.0/src/honcho_cli/replay.py +702 -0
- honcho_cli-0.6.0/src/honcho_cli/replay_view.py +415 -0
- honcho_cli-0.6.0/tests/test_replay.py +860 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/.gitignore +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/scripts/generate_cli_docs.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/__init__.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/agents.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/branding.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/__init__.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/conclusion.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/config_cmd.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/dream.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/install.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/message.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/peer.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/scope.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/session.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/setup.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/commands/stack.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/config.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/__init__.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/docker.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/env.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/health.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/profile.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/setup.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/templates/__init__.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/templates/docker-compose.yml +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/local/templates/init.sql +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/main.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/oauth.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/output.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/recall.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/update_check.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/src/honcho_cli/validation.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/__init__.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/conftest.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_commands.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_common.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_conclusion_attribution.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_config.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_dream.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_install.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_local.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_oauth.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_output.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_recall.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_setup.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_start.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_validation.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/tests/test_version.py +0 -0
- {honcho_cli-0.5.0 → honcho_cli-0.6.0}/uv.lock +0 -0
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [0.6.0] - 2026-11-10
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `honcho workspace replay --from <id> --to <id>`: copy a workspace by replaying it. Workspace, peer and session metadata and configuration, session membership and scopes are copied, then every message is re-sent in order with its original `created_at`, so the destination derives its own conclusions, summaries and peer cards; nothing derived is copied. `--from-url` / `--to-url` (and `HONCHO_FROM_API_KEY` / `HONCHO_TO_API_KEY`) put either side on another Honcho instance, and the configured credentials are never sent to an instance they were not issued for. `--num-sessions N` replays only the N sessions with the most recent message, `--dry-run` reads both sides without writing and says, for each session, whether a replay will create it, resume it, find it up to date, or skip it as a conflict, and a rerun resumes by skipping messages the destination already has. A destination session whose messages differ from the source is left untouched and reported. In a terminal the command prints a short report and the `queue-status` command that shows derivation on the destination; `--json` prints the same facts as one object. Both reports count the conclusions in the source (`not_copied`), because conclusions and peer cards written through the API have no source message and are not recreated. The destination session has the source's current members from its first message, so a peer that joined late observes the whole session. With a workspace-scoped key, a source that has no sessions and no peers is reported as `NOTHING_TO_REPLAY` and is not created. Per-message configuration is not stored by Honcho and cannot be replayed (#1573)
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- `honcho --version`, the update check and the `X-Honcho-Host` header report the installed version. `__version__` was a hardcoded string that the 0.5.0 release did not bump, so a 0.5.0 install reported itself as 0.4.0, and the update check told 0.5.0 users that 0.5.0 was available. The version is now read from the installed package metadata (#1571)
|
|
17
|
+
|
|
8
18
|
## [0.5.0] - 2026-11-05
|
|
9
19
|
|
|
10
20
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: honcho-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: A terminal for Honcho — memory that reasons.
|
|
5
5
|
Project-URL: Homepage, https://github.com/plastic-labs/honcho
|
|
6
6
|
Project-URL: Repository, https://github.com/plastic-labs/honcho
|
|
@@ -107,6 +107,7 @@ honcho stop --wipe # also delete volumes
|
|
|
107
107
|
| `honcho workspace chat <query>` | Query the dialectic across all peers (optional `-s` / `--scope` / `--reasoning`) |
|
|
108
108
|
| `honcho workspace search <query>` | Search messages across workspace |
|
|
109
109
|
| `honcho workspace queue-status` | Deriver queue status (filter with `--observer` / `--sender`) |
|
|
110
|
+
| `honcho workspace replay --from <id> --to <id>` | Copy a workspace by re-sending its messages, so the destination derives its own memory. `--to-url` / `--from-url` for another instance, `--num-sessions N` for the N most recently active sessions, `--dry-run` to preview |
|
|
110
111
|
| `honcho workspace delete <id>` | Delete a workspace. Use `--dry-run` to preview, `--cascade` to also delete sessions, `--yes` to skip the confirm prompt |
|
|
111
112
|
|
|
112
113
|
### Peers
|
|
@@ -235,6 +236,8 @@ Precedence (highest first): **flag → env var → config file → default**.
|
|
|
235
236
|
| `HONCHO_JSON` | `--json` | Force JSON output (`1` / `true`) |
|
|
236
237
|
| `HONCHO_NO_UPDATE_CHECK` | — | Disable the once-a-day upgrade notice (`1` / `true`) |
|
|
237
238
|
| `HONCHO_PROFILE` | `--profile` (start/stop/status) | Local stack profile (default: `local`) |
|
|
239
|
+
| `HONCHO_FROM_URL` / `HONCHO_FROM_API_KEY` | `--from-url` (workspace replay); the key has no flag | Source instance, when it is not the configured one |
|
|
240
|
+
| `HONCHO_TO_URL` / `HONCHO_TO_API_KEY` | `--to-url` (workspace replay); the key has no flag | Destination instance, when it is not the configured one |
|
|
238
241
|
| `LLM_OPENAI_API_KEY` | — | Provider key for `honcho start` (also `LLM_ANTHROPIC_API_KEY`, `LLM_GEMINI_API_KEY`) |
|
|
239
242
|
|
|
240
243
|
```bash
|
|
@@ -80,6 +80,7 @@ honcho stop --wipe # also delete volumes
|
|
|
80
80
|
| `honcho workspace chat <query>` | Query the dialectic across all peers (optional `-s` / `--scope` / `--reasoning`) |
|
|
81
81
|
| `honcho workspace search <query>` | Search messages across workspace |
|
|
82
82
|
| `honcho workspace queue-status` | Deriver queue status (filter with `--observer` / `--sender`) |
|
|
83
|
+
| `honcho workspace replay --from <id> --to <id>` | Copy a workspace by re-sending its messages, so the destination derives its own memory. `--to-url` / `--from-url` for another instance, `--num-sessions N` for the N most recently active sessions, `--dry-run` to preview |
|
|
83
84
|
| `honcho workspace delete <id>` | Delete a workspace. Use `--dry-run` to preview, `--cascade` to also delete sessions, `--yes` to skip the confirm prompt |
|
|
84
85
|
|
|
85
86
|
### Peers
|
|
@@ -208,6 +209,8 @@ Precedence (highest first): **flag → env var → config file → default**.
|
|
|
208
209
|
| `HONCHO_JSON` | `--json` | Force JSON output (`1` / `true`) |
|
|
209
210
|
| `HONCHO_NO_UPDATE_CHECK` | — | Disable the once-a-day upgrade notice (`1` / `true`) |
|
|
210
211
|
| `HONCHO_PROFILE` | `--profile` (start/stop/status) | Local stack profile (default: `local`) |
|
|
212
|
+
| `HONCHO_FROM_URL` / `HONCHO_FROM_API_KEY` | `--from-url` (workspace replay); the key has no flag | Source instance, when it is not the configured one |
|
|
213
|
+
| `HONCHO_TO_URL` / `HONCHO_TO_API_KEY` | `--to-url` (workspace replay); the key has no flag | Destination instance, when it is not the configured one |
|
|
211
214
|
| `LLM_OPENAI_API_KEY` | — | Provider key for `honcho start` (also `LLM_ANTHROPIC_API_KEY`, `LLM_GEMINI_API_KEY`) |
|
|
212
215
|
|
|
213
216
|
```bash
|
|
@@ -82,6 +82,7 @@ def print_welcome(console: Console) -> None:
|
|
|
82
82
|
("[dim]example[/dim]", "[dim]honcho peer chat \"what does alice prefer?\" -p alice -w agents[/dim]"),
|
|
83
83
|
("", ""),
|
|
84
84
|
("workspace", "list · create · search · chat · delete · inspect · queue-status"),
|
|
85
|
+
("", "replay"),
|
|
85
86
|
("peer", "list · create · search · inspect · card · chat"),
|
|
86
87
|
("", "get-metadata · set-metadata · representation"),
|
|
87
88
|
("session", "list · create · search · delete · inspect · view · add-peers"),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"""Workspace commands: list, inspect, create, delete, search, chat, queue-status."""
|
|
1
|
+
"""Workspace commands: list, inspect, create, delete, search, chat, queue-status, replay."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import os
|
|
7
|
+
import time
|
|
6
8
|
from typing import Optional
|
|
7
9
|
|
|
8
10
|
import typer
|
|
@@ -16,13 +18,15 @@ from honcho import (
|
|
|
16
18
|
ServerError,
|
|
17
19
|
)
|
|
18
20
|
|
|
21
|
+
from honcho_cli import replay as replay_lib
|
|
22
|
+
from honcho_cli import replay_view
|
|
19
23
|
from honcho_cli.config import identity_headers
|
|
20
|
-
from honcho_cli.output import print_error, print_result, status, use_json
|
|
24
|
+
from honcho_cli.output import print_error, print_json, print_result, status, use_json
|
|
21
25
|
from honcho_cli.recall import parse_csv_repeatable, reject_incompatible_recall, scope_for_sdk
|
|
22
26
|
from honcho_cli.validation import validate_resource_id
|
|
23
27
|
|
|
24
28
|
from honcho_cli._help import HonchoTyperGroup
|
|
25
|
-
from honcho_cli.common import add_common_options, format_evidence, get_client, get_flag_overrides, get_resolved_config, handle_cmd_flags
|
|
29
|
+
from honcho_cli.common import add_common_options, format_evidence, get_client, get_endpoint_client, get_flag_overrides, get_resolved_config, handle_cmd_flags, same_instance
|
|
26
30
|
|
|
27
31
|
app = typer.Typer(cls=HonchoTyperGroup, help="List, create, inspect, chat, delete, and search workspaces.")
|
|
28
32
|
add_common_options(app)
|
|
@@ -328,6 +332,187 @@ def queue_status(
|
|
|
328
332
|
_handle_error(e, "queue", "status")
|
|
329
333
|
|
|
330
334
|
|
|
335
|
+
@app.command()
|
|
336
|
+
def replay(
|
|
337
|
+
source: str = typer.Option(..., "--from", help="Source workspace ID"),
|
|
338
|
+
dest: Optional[str] = typer.Option(
|
|
339
|
+
None,
|
|
340
|
+
"--to",
|
|
341
|
+
help="Destination workspace ID. Defaults to the --from ID, which needs a different destination instance.",
|
|
342
|
+
),
|
|
343
|
+
from_url: Optional[str] = typer.Option(
|
|
344
|
+
None, "--from-url", envvar="HONCHO_FROM_URL",
|
|
345
|
+
help="Source Honcho URL, when it is not the configured instance. Its API key is read from HONCHO_FROM_API_KEY.",
|
|
346
|
+
),
|
|
347
|
+
to_url: Optional[str] = typer.Option(
|
|
348
|
+
None, "--to-url", envvar="HONCHO_TO_URL",
|
|
349
|
+
help="Destination Honcho URL, when it is not the configured instance. Its API key is read from HONCHO_TO_API_KEY.",
|
|
350
|
+
),
|
|
351
|
+
num_sessions: Optional[int] = typer.Option(
|
|
352
|
+
None, "--num-sessions", min=1,
|
|
353
|
+
help="Replay only the N sessions with the most recent message",
|
|
354
|
+
),
|
|
355
|
+
dry_run: bool = typer.Option(False, "--dry-run", help="Show what a replay would do with each session, without writing anything"),
|
|
356
|
+
json_output: bool = typer.Option(False, "--json", help="Force JSON output"),
|
|
357
|
+
) -> None:
|
|
358
|
+
"""Replay a workspace's sessions into another workspace, on this or another instance.
|
|
359
|
+
|
|
360
|
+
Copies workspace, peer and session settings, then re-sends every message in
|
|
361
|
+
order with its original timestamp. The destination derives its own
|
|
362
|
+
conclusions; conclusions and peer cards are not copied, so the ones written
|
|
363
|
+
through the API are not recreated. Rerunning resumes: messages already in
|
|
364
|
+
the destination are skipped.
|
|
365
|
+
|
|
366
|
+
Each side uses the configured instance unless its URL is given. A side on
|
|
367
|
+
another instance needs its own API key, read from HONCHO_FROM_API_KEY /
|
|
368
|
+
HONCHO_TO_API_KEY; the configured credentials are never sent to it.
|
|
369
|
+
"""
|
|
370
|
+
handle_cmd_flags(json_output=json_output)
|
|
371
|
+
# Keys come from the environment only: a key passed as an argument shows up
|
|
372
|
+
# in process listings and shell history.
|
|
373
|
+
from_api_key = os.environ.get("HONCHO_FROM_API_KEY") or None
|
|
374
|
+
to_api_key = os.environ.get("HONCHO_TO_API_KEY") or None
|
|
375
|
+
source_id = validate_resource_id(source, "workspace")
|
|
376
|
+
dest_id = validate_resource_id(dest or source, "workspace")
|
|
377
|
+
|
|
378
|
+
source_client = get_endpoint_client(workspace_id=source_id, base_url=from_url, api_key=from_api_key)
|
|
379
|
+
dest_client = get_endpoint_client(workspace_id=dest_id, base_url=to_url, api_key=to_api_key)
|
|
380
|
+
source_ref = {"url": source_client.base_url, "workspace_id": source_id}
|
|
381
|
+
|
|
382
|
+
if source_id == dest_id and same_instance(source_client.base_url, dest_client.base_url):
|
|
383
|
+
print_error(
|
|
384
|
+
"SAME_WORKSPACE",
|
|
385
|
+
"Source and destination are the same workspace. Pass a different --to, or --to-url for another instance.",
|
|
386
|
+
{"workspace": source_id, "url": source_client.base_url},
|
|
387
|
+
)
|
|
388
|
+
raise typer.Exit(1)
|
|
389
|
+
|
|
390
|
+
started = time.monotonic()
|
|
391
|
+
replayer = replay_lib.Replayer(source_client, dest_client)
|
|
392
|
+
all_peers = num_sessions is None
|
|
393
|
+
|
|
394
|
+
with replay_view.Reporter() as progress:
|
|
395
|
+
# Read the source, and look at the destination without writing to it.
|
|
396
|
+
try:
|
|
397
|
+
progress.phase(f"Reading source workspace '{source_id}'")
|
|
398
|
+
metadata, configuration = replay_lib.read_workspace(source_client)
|
|
399
|
+
plans = replay_lib.list_sessions(source_client)
|
|
400
|
+
sessions_in_source = len(plans)
|
|
401
|
+
if num_sessions is not None or dry_run:
|
|
402
|
+
replay_lib.probe_sessions(plans, progress.tick)
|
|
403
|
+
if num_sessions is not None:
|
|
404
|
+
plans = replay_lib.select_most_recent(plans, num_sessions)
|
|
405
|
+
not_copied = {
|
|
406
|
+
"conclusions_in_source": replay_lib.count_conclusions(source_client),
|
|
407
|
+
"note": replay_lib.NOT_COPIED_NOTE,
|
|
408
|
+
}
|
|
409
|
+
except replay_lib.NothingToReplay as e:
|
|
410
|
+
print_error("NOTHING_TO_REPLAY", str(e), {"workspace": source_id})
|
|
411
|
+
raise typer.Exit(1) from e
|
|
412
|
+
except Exception as e:
|
|
413
|
+
_handle_error(e, "workspace", source_id)
|
|
414
|
+
return
|
|
415
|
+
|
|
416
|
+
try:
|
|
417
|
+
progress.phase(f"Checking destination workspace '{dest_id}'")
|
|
418
|
+
dest_sessions = replayer.destination_session_count()
|
|
419
|
+
dest_ref = {"url": dest_client.base_url, "workspace_id": dest_id, "sessions": dest_sessions}
|
|
420
|
+
if dry_run:
|
|
421
|
+
replayer.check_sessions(plans, progress.tick)
|
|
422
|
+
peer_ids = replayer.peers_for(plans, all_peers=all_peers)
|
|
423
|
+
peers_in_destination = replayer.peers_in_destination(peer_ids)
|
|
424
|
+
except replay_lib.ReadOnlyUnsupported as e:
|
|
425
|
+
print_error("SDK_UNSUPPORTED", str(e), {})
|
|
426
|
+
raise typer.Exit(1) from e
|
|
427
|
+
except Exception as e:
|
|
428
|
+
_handle_error(e, "workspace", dest_id)
|
|
429
|
+
return
|
|
430
|
+
|
|
431
|
+
if not dry_run:
|
|
432
|
+
progress.line(
|
|
433
|
+
f"Replaying {len(plans)} of {replay_view.plural(sessions_in_source, 'session')} "
|
|
434
|
+
f"from '{source_id}' ({source_client.base_url}) "
|
|
435
|
+
f"to '{dest_id}' ({dest_client.base_url})"
|
|
436
|
+
+ (f". The destination already has {replay_view.plural(dest_sessions, 'session')}." if dest_sessions else "")
|
|
437
|
+
)
|
|
438
|
+
progress.phase("Copying peers and sessions")
|
|
439
|
+
try:
|
|
440
|
+
result = replay_lib.replay(
|
|
441
|
+
replayer,
|
|
442
|
+
plans,
|
|
443
|
+
workspace_metadata=metadata,
|
|
444
|
+
workspace_configuration=configuration,
|
|
445
|
+
all_peers=all_peers,
|
|
446
|
+
on_progress=progress.line,
|
|
447
|
+
on_tick=progress.tick,
|
|
448
|
+
)
|
|
449
|
+
except Exception as e:
|
|
450
|
+
_handle_error(e, "workspace", dest_id)
|
|
451
|
+
return
|
|
452
|
+
|
|
453
|
+
if dry_run:
|
|
454
|
+
report = {
|
|
455
|
+
"dry_run": True,
|
|
456
|
+
"source": source_ref,
|
|
457
|
+
"destination": dest_ref,
|
|
458
|
+
"sessions_in_source": sessions_in_source,
|
|
459
|
+
"sessions_to_replay": len(plans),
|
|
460
|
+
"actions": {
|
|
461
|
+
action: sum(1 for plan in plans if plan.action == action)
|
|
462
|
+
for action in ("create", "resume", "up_to_date", "conflict")
|
|
463
|
+
},
|
|
464
|
+
"messages_in_sessions": sum(plan.message_count or 0 for plan in plans),
|
|
465
|
+
"messages_to_send": sum(plan.messages_to_send for plan in plans),
|
|
466
|
+
"peers_to_copy": len(peer_ids),
|
|
467
|
+
"peers_in_destination": len(peers_in_destination),
|
|
468
|
+
"workspace_settings_copied": dest_sessions == 0,
|
|
469
|
+
"not_copied": not_copied,
|
|
470
|
+
"sessions": [plan.to_dict() for plan in plans],
|
|
471
|
+
}
|
|
472
|
+
if use_json():
|
|
473
|
+
print_json(report)
|
|
474
|
+
else:
|
|
475
|
+
replay_view.print_plan(report)
|
|
476
|
+
return
|
|
477
|
+
|
|
478
|
+
messages_created = sum(s.messages_created for s in result.sessions)
|
|
479
|
+
report = {
|
|
480
|
+
"source": source_ref,
|
|
481
|
+
"destination": dest_ref,
|
|
482
|
+
"sessions_in_source": sessions_in_source,
|
|
483
|
+
"sessions_replayed": len(result.sessions),
|
|
484
|
+
"sessions_failed": len(result.failed),
|
|
485
|
+
"actions": {
|
|
486
|
+
action: sum(1 for s in result.sessions if s.action == action)
|
|
487
|
+
for action in ("created", "resumed", "up_to_date")
|
|
488
|
+
},
|
|
489
|
+
"messages_created": messages_created,
|
|
490
|
+
"messages_skipped": sum(s.messages_skipped for s in result.sessions),
|
|
491
|
+
"peers_created": result.peers_created,
|
|
492
|
+
"peers_existing": result.peers_existing,
|
|
493
|
+
"workspace_settings_copied": result.workspace_copied,
|
|
494
|
+
"not_copied": not_copied,
|
|
495
|
+
"elapsed_seconds": round(time.monotonic() - started, 1),
|
|
496
|
+
"check_derivation": _queue_status_command(dest_client.base_url, dest_id) if messages_created else None,
|
|
497
|
+
"sessions": [s.to_dict() for s in result.sessions],
|
|
498
|
+
"failed": result.failed,
|
|
499
|
+
}
|
|
500
|
+
if use_json():
|
|
501
|
+
print_json(report)
|
|
502
|
+
else:
|
|
503
|
+
replay_view.print_summary(report)
|
|
504
|
+
if result.failed:
|
|
505
|
+
raise typer.Exit(1)
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def _queue_status_command(dest_url: str, dest_id: str) -> str:
|
|
509
|
+
"""The command that shows the destination's derivation queue after a replay."""
|
|
510
|
+
command = f"honcho workspace queue-status -w {dest_id}"
|
|
511
|
+
if same_instance(dest_url, get_resolved_config().base_url):
|
|
512
|
+
return command
|
|
513
|
+
return f'HONCHO_BASE_URL={dest_url} HONCHO_API_KEY="$HONCHO_TO_API_KEY" {command}'
|
|
514
|
+
|
|
515
|
+
|
|
331
516
|
def _with_workspace(client, workspace_id: str):
|
|
332
517
|
"""Return a new client pointed at a different workspace."""
|
|
333
518
|
return Honcho(
|
|
@@ -12,6 +12,7 @@ no-op if the same flag was already set at an outer level.
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
+
import os
|
|
15
16
|
from dataclasses import replace
|
|
16
17
|
from typing import Optional
|
|
17
18
|
|
|
@@ -20,7 +21,7 @@ import typer
|
|
|
20
21
|
from honcho import Honcho
|
|
21
22
|
|
|
22
23
|
from honcho_cli import oauth
|
|
23
|
-
from honcho_cli.config import CLIConfig, OAuthTokens, get_client_kwargs
|
|
24
|
+
from honcho_cli.config import ENV_MAP, CLIConfig, OAuthTokens, get_client_kwargs, identity_headers
|
|
24
25
|
from honcho_cli.output import print_error, set_json_mode
|
|
25
26
|
from honcho_cli.validation import validate_resource_id
|
|
26
27
|
|
|
@@ -131,6 +132,52 @@ def get_client(*, require_workspace: bool = True):
|
|
|
131
132
|
return Honcho(**get_client_kwargs(config)), config
|
|
132
133
|
|
|
133
134
|
|
|
135
|
+
def same_instance(url_a: str, url_b: str) -> bool:
|
|
136
|
+
"""True when two base URLs name the same Honcho instance."""
|
|
137
|
+
return url_a.rstrip("/") == url_b.rstrip("/")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_endpoint_client(
|
|
141
|
+
*,
|
|
142
|
+
workspace_id: str,
|
|
143
|
+
base_url: str | None = None,
|
|
144
|
+
api_key: str | None = None,
|
|
145
|
+
) -> Honcho:
|
|
146
|
+
"""Create a client for one side of a command that spans two instances.
|
|
147
|
+
|
|
148
|
+
With no overrides this is the configured instance and its credentials. An
|
|
149
|
+
explicit ``api_key`` always wins. A ``base_url`` that names a different
|
|
150
|
+
instance never receives the configured credentials: they belong to another
|
|
151
|
+
host, so that side authenticates with its own ``api_key`` or, for an
|
|
152
|
+
instance with auth disabled, with nothing.
|
|
153
|
+
"""
|
|
154
|
+
config = CLIConfig.load()
|
|
155
|
+
url = base_url or config.base_url
|
|
156
|
+
key = api_key
|
|
157
|
+
if not key and same_instance(url, config.base_url):
|
|
158
|
+
maybe_refresh_token(config)
|
|
159
|
+
key = config.resolved_api_key()
|
|
160
|
+
|
|
161
|
+
kwargs: dict = {
|
|
162
|
+
"base_url": url,
|
|
163
|
+
"workspace_id": workspace_id,
|
|
164
|
+
"default_headers": identity_headers(),
|
|
165
|
+
}
|
|
166
|
+
if key:
|
|
167
|
+
return Honcho(api_key=key, **kwargs)
|
|
168
|
+
|
|
169
|
+
# Given no key, the SDK reads HONCHO_API_KEY itself. Hide it while the
|
|
170
|
+
# client is built, or a key meant for the configured instance would be sent
|
|
171
|
+
# to this one.
|
|
172
|
+
env_key = ENV_MAP["api_key"]
|
|
173
|
+
hidden = os.environ.pop(env_key, None)
|
|
174
|
+
try:
|
|
175
|
+
return Honcho(**kwargs)
|
|
176
|
+
finally:
|
|
177
|
+
if hidden is not None:
|
|
178
|
+
os.environ[env_key] = hidden
|
|
179
|
+
|
|
180
|
+
|
|
134
181
|
def handle_cmd_flags(
|
|
135
182
|
json_output: bool = False,
|
|
136
183
|
workspace: str | None = None,
|