reviso-cli 0.2.0__tar.gz → 0.3.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.
- {reviso_cli-0.2.0/src/reviso_cli.egg-info → reviso_cli-0.3.0}/PKG-INFO +25 -13
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/README.md +23 -12
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/pyproject.toml +2 -2
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/__init__.py +1 -1
- reviso_cli-0.3.0/src/reviso_cli/cli/__init__.py +490 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/credentials.py +63 -2
- reviso_cli-0.3.0/src/reviso_cli/cli/deck.py +81 -0
- reviso_cli-0.3.0/src/reviso_cli/cli/dsh_credentials.py +125 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/guest_comments.py +2 -1
- reviso_cli-0.3.0/src/reviso_cli/cli/preflight.py +34 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/versions.py +45 -10
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/client/__init__.py +100 -26
- reviso_cli-0.3.0/src/reviso_cli/client/errors.py +55 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/client/http.py +4 -2
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/client/participation.py +3 -1
- reviso_cli-0.3.0/src/reviso_cli/deck_assets.py +138 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/local.py +28 -11
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/scope.py +6 -4
- {reviso_cli-0.2.0 → reviso_cli-0.3.0/src/reviso_cli.egg-info}/PKG-INFO +25 -13
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli.egg-info/SOURCES.txt +12 -1
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli.egg-info/requires.txt +1 -0
- reviso_cli-0.3.0/tests/test_ci_tier.py +141 -0
- reviso_cli-0.3.0/tests/test_cli_deck_validate.py +113 -0
- reviso_cli-0.3.0/tests/test_cli_documents_paging.py +90 -0
- reviso_cli-0.3.0/tests/test_cli_publish_duplicate_hint.py +81 -0
- reviso_cli-0.3.0/tests/test_client.py +582 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/tests/test_credentials.py +16 -3
- reviso_cli-0.3.0/tests/test_deck_assets.py +91 -0
- reviso_cli-0.3.0/tests/test_dsh_fallback.py +213 -0
- reviso_cli-0.3.0/tests/test_publish_preflight.py +61 -0
- reviso_cli-0.2.0/src/reviso_cli/cli/__init__.py +0 -265
- reviso_cli-0.2.0/src/reviso_cli/client/errors.py +0 -28
- reviso_cli-0.2.0/tests/test_client.py +0 -211
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/LICENSE +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/setup.cfg +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/__main__.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/access.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/auth.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/credential_file.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/doctor.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/invites.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/oauth_http.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/cli/oauth_login.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/client/collab.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/command_journal.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/document_route_keys.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/document_search.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/errors.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/ids.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/origin.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli/paths.py +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli.egg-info/dependency_links.txt +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli.egg-info/entry_points.txt +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/src/reviso_cli.egg-info/top_level.txt +0 -0
- {reviso_cli-0.2.0 → reviso_cli-0.3.0}/tests/test_oauth_login.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: reviso-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Command line client for Reviso: publish drafts for human review, read reviewer comments back, and publish revisions safely.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -46,6 +46,7 @@ Description-Content-Type: text/markdown
|
|
|
46
46
|
License-File: LICENSE
|
|
47
47
|
Provides-Extra: test
|
|
48
48
|
Requires-Dist: pytest>=8.0; extra == "test"
|
|
49
|
+
Requires-Dist: ruff<0.16,>=0.15.6; extra == "test"
|
|
49
50
|
Dynamic: license-file
|
|
50
51
|
|
|
51
52
|
# reviso-cli
|
|
@@ -79,6 +80,8 @@ reviso doctor --json
|
|
|
79
80
|
|
|
80
81
|
reviso publish draft.md --title "Q3 launch plan" --description "Initial draft"
|
|
81
82
|
# prints the document URL
|
|
83
|
+
reviso publish draft.md --title "Q3 launch plan" --json
|
|
84
|
+
# prints document_id, version_id, workspace_id, and review_url
|
|
82
85
|
|
|
83
86
|
reviso documents --json # find the document id
|
|
84
87
|
reviso packet doc_abc123 --format json # reviewer comments and version metadata
|
|
@@ -104,19 +107,23 @@ The credential lock currently supports macOS and Linux.
|
|
|
104
107
|
|
|
105
108
|
## The rule that matters
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
**`update` and `rollback` require `--base-version-id`.**
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
The base is the version you actually read. Without it, a write could silently
|
|
113
|
+
discard a human's concurrent edit, so the CLI fails before contacting the server.
|
|
114
|
+
The safe shape is two steps:
|
|
112
115
|
|
|
113
116
|
```bash
|
|
114
117
|
reviso versions <document_id> # take the newest version_id
|
|
115
118
|
reviso update <document_id> file --description "..." --base-version-id <ver_...>
|
|
119
|
+
reviso rollback <document_id> <target_version_id> \
|
|
120
|
+
--description "..." --base-version-id <ver_...>
|
|
116
121
|
```
|
|
117
122
|
|
|
118
|
-
If
|
|
119
|
-
the human's edit.
|
|
123
|
+
If a write is rejected as a conflict, re-read and re-apply your change on top of
|
|
124
|
+
the human's edit. `--force-latest` is the explicit last-writer-wins opt-in: it
|
|
125
|
+
performs one fresh read and uses that version as the base. It cannot be combined
|
|
126
|
+
with `--base-version-id`.
|
|
120
127
|
|
|
121
128
|
## Command groups
|
|
122
129
|
|
|
@@ -143,13 +150,18 @@ If you need MCP tools rather than a shell, the hosted connector is the better
|
|
|
143
150
|
path in most hosts. See [reviso-agent](https://github.com/reviso-si/reviso-agent)
|
|
144
151
|
for the agent skill.
|
|
145
152
|
|
|
146
|
-
##
|
|
153
|
+
## Provenance
|
|
147
154
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
Publishing from an agent runtime binds provenance automatically when the runtime
|
|
156
|
+
exposes `DSH_SESSION_ID`. You can pass an explicit pair instead:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
reviso publish draft.md --source-kind dsh --source-session-id <session_id>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`--source-kind` and `--source-session-id` must be supplied together. Use
|
|
163
|
+
`--no-source-binding` for an intentional no-source publish; it cannot be combined
|
|
164
|
+
with either provenance flag.
|
|
153
165
|
|
|
154
166
|
## License
|
|
155
167
|
|
|
@@ -29,6 +29,8 @@ reviso doctor --json
|
|
|
29
29
|
|
|
30
30
|
reviso publish draft.md --title "Q3 launch plan" --description "Initial draft"
|
|
31
31
|
# prints the document URL
|
|
32
|
+
reviso publish draft.md --title "Q3 launch plan" --json
|
|
33
|
+
# prints document_id, version_id, workspace_id, and review_url
|
|
32
34
|
|
|
33
35
|
reviso documents --json # find the document id
|
|
34
36
|
reviso packet doc_abc123 --format json # reviewer comments and version metadata
|
|
@@ -54,19 +56,23 @@ The credential lock currently supports macOS and Linux.
|
|
|
54
56
|
|
|
55
57
|
## The rule that matters
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
**`update` and `rollback` require `--base-version-id`.**
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
The base is the version you actually read. Without it, a write could silently
|
|
62
|
+
discard a human's concurrent edit, so the CLI fails before contacting the server.
|
|
63
|
+
The safe shape is two steps:
|
|
62
64
|
|
|
63
65
|
```bash
|
|
64
66
|
reviso versions <document_id> # take the newest version_id
|
|
65
67
|
reviso update <document_id> file --description "..." --base-version-id <ver_...>
|
|
68
|
+
reviso rollback <document_id> <target_version_id> \
|
|
69
|
+
--description "..." --base-version-id <ver_...>
|
|
66
70
|
```
|
|
67
71
|
|
|
68
|
-
If
|
|
69
|
-
the human's edit.
|
|
72
|
+
If a write is rejected as a conflict, re-read and re-apply your change on top of
|
|
73
|
+
the human's edit. `--force-latest` is the explicit last-writer-wins opt-in: it
|
|
74
|
+
performs one fresh read and uses that version as the base. It cannot be combined
|
|
75
|
+
with `--base-version-id`.
|
|
70
76
|
|
|
71
77
|
## Command groups
|
|
72
78
|
|
|
@@ -93,13 +99,18 @@ If you need MCP tools rather than a shell, the hosted connector is the better
|
|
|
93
99
|
path in most hosts. See [reviso-agent](https://github.com/reviso-si/reviso-agent)
|
|
94
100
|
for the agent skill.
|
|
95
101
|
|
|
96
|
-
##
|
|
102
|
+
## Provenance
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
Publishing from an agent runtime binds provenance automatically when the runtime
|
|
105
|
+
exposes `DSH_SESSION_ID`. You can pass an explicit pair instead:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
reviso publish draft.md --source-kind dsh --source-session-id <session_id>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`--source-kind` and `--source-session-id` must be supplied together. Use
|
|
112
|
+
`--no-source-binding` for an intentional no-source publish; it cannot be combined
|
|
113
|
+
with either provenance flag.
|
|
103
114
|
|
|
104
115
|
## License
|
|
105
116
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "reviso-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Command line client for Reviso: publish drafts for human review, read reviewer comments back, and publish revisions safely."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -26,7 +26,7 @@ classifiers = [
|
|
|
26
26
|
dependencies = []
|
|
27
27
|
|
|
28
28
|
[project.optional-dependencies]
|
|
29
|
-
test = ["pytest>=8.0"]
|
|
29
|
+
test = ["pytest>=8.0", "ruff>=0.15.6,<0.16"]
|
|
30
30
|
|
|
31
31
|
# PyPI renders these as the package page's links. Without them the page is a
|
|
32
32
|
# dead end: someone who finds the package by search has no route to the docs,
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
"""Command line dispatcher. Every server call goes through RevisoClient."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import hashlib
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from .. import command_journal
|
|
13
|
+
from ..client import RevisoClient, publish_request_body
|
|
14
|
+
from ..deck_assets import asset_request, find_images, payload_summary, rewrite
|
|
15
|
+
from ..document_search import search_documents
|
|
16
|
+
from ..errors import ValidationError
|
|
17
|
+
from ..local import canonical_review_url, read_mapping, write_mapping
|
|
18
|
+
from ..origin import DEFAULT_SERVER_URL
|
|
19
|
+
from ..paths import config_path, packet_path, read_json, write_json
|
|
20
|
+
from ..scope import resolve_agent_create_scope
|
|
21
|
+
from .doctor import doctor_report, print_doctor
|
|
22
|
+
from .auth import AuthenticatedClient, auth_command
|
|
23
|
+
from .credentials import access_token, selected_server
|
|
24
|
+
from .dsh_credentials import dsh_workspace
|
|
25
|
+
from .oauth_http import server_origin
|
|
26
|
+
from .deck import cmd_deck_validate
|
|
27
|
+
from .preflight import check_publish_size
|
|
28
|
+
from .guest_comments import add_guest_comment_commands
|
|
29
|
+
from .invites import add_invite_commands
|
|
30
|
+
from .versions import add_version_commands, format_file_arg
|
|
31
|
+
|
|
32
|
+
# Response blocks that are browser UI state. The human status line drops them;
|
|
33
|
+
# --json keeps them.
|
|
34
|
+
ACCESS_KEYS = ("effective_access", "security_policy")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _load_config() -> dict:
|
|
38
|
+
path = config_path()
|
|
39
|
+
if path.exists():
|
|
40
|
+
return read_json(path)
|
|
41
|
+
return {}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _server_url() -> str:
|
|
45
|
+
return server_origin(selected_server(_load_config()) or DEFAULT_SERVER_URL)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _automation_key(cfg: dict) -> str:
|
|
49
|
+
return access_token(_server_url(), cfg)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _client() -> RevisoClient:
|
|
53
|
+
return AuthenticatedClient(_server_url(), None, _load_config())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def cmd_auth(args: argparse.Namespace) -> None:
|
|
57
|
+
auth_command(args, _load_config())
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _declared_deck(content: str) -> bool:
|
|
61
|
+
return 'class="hr-deck"' in content or "class='hr-deck'" in content
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _draft_content(fmt: str, title: str, kind: str | None) -> str:
|
|
65
|
+
"""Small host document that can own uploaded assets before final publish."""
|
|
66
|
+
safe_title = (title.replace("&", "&").replace("<", "<")
|
|
67
|
+
.replace(">", ">"))
|
|
68
|
+
if fmt == "html" and kind == "html_deck":
|
|
69
|
+
return ('<div class="hr-deck" data-aspect-ratio="16:9" '
|
|
70
|
+
'data-contract-version="html-deck/1">'
|
|
71
|
+
'<section class="hr-slide" data-slide-id="s01">'
|
|
72
|
+
f'<h1>{safe_title}</h1><p>Uploading images...</p>'
|
|
73
|
+
'</section></div>')
|
|
74
|
+
if fmt == "html":
|
|
75
|
+
return f"<article><h1>{safe_title}</h1><p>Uploading images...</p></article>"
|
|
76
|
+
return "# Uploading images...\n"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _upload_embedded_images(client: RevisoClient, *, document_id: str,
|
|
80
|
+
content: str, path: Path, op: str) -> str:
|
|
81
|
+
uploads = []
|
|
82
|
+
for index, image in enumerate(find_images(content)):
|
|
83
|
+
digest = hashlib.sha256(image.decoded).hexdigest()[:24]
|
|
84
|
+
extension = image.mime.split("/", 1)[1].replace("jpeg", "jpg")
|
|
85
|
+
uploaded = client.upload_image(
|
|
86
|
+
document_id,
|
|
87
|
+
**asset_request(
|
|
88
|
+
image,
|
|
89
|
+
file_name=f"{path.stem}-{index + 1}.{extension}",
|
|
90
|
+
operation_id=f"{op}-asset-{index}-{digest}"[:199],
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
url = str(uploaded.get("url") or "")
|
|
94
|
+
if not url:
|
|
95
|
+
raise RuntimeError("image upload returned no asset URL")
|
|
96
|
+
uploads.append((image, url))
|
|
97
|
+
return rewrite(content, uploads)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def cmd_publish(args: argparse.Namespace) -> None:
|
|
101
|
+
path = Path(args.file)
|
|
102
|
+
scope = _workspace_scope(args.workspace_id or "", args.parent_id or "")
|
|
103
|
+
content = path.read_text()
|
|
104
|
+
fmt = format_file_arg(args, path)
|
|
105
|
+
title = args.title or path.name
|
|
106
|
+
kind, contract = args.kind, args.deck_contract_version
|
|
107
|
+
options = {key: value for key, value in (("document_kind", kind), ("deck_contract_version", contract)) if value is not None}
|
|
108
|
+
source_kind, source_session_id = _source_binding(args)
|
|
109
|
+
if source_kind is not None:
|
|
110
|
+
options["source_kind"] = source_kind
|
|
111
|
+
options["source_session_id"] = source_session_id
|
|
112
|
+
# A journaled operation_id is reused across reruns of THIS command, so a
|
|
113
|
+
# crashed-then-rerun publish replays instead of double-creating. Cleared
|
|
114
|
+
# only after every local success step has completed.
|
|
115
|
+
parts = [title, content, fmt, args.description or "",
|
|
116
|
+
scope.workspace_id, scope.parent_id]
|
|
117
|
+
if options:
|
|
118
|
+
parts.extend([kind or "", contract or "",
|
|
119
|
+
source_kind or "", source_session_id or ""])
|
|
120
|
+
op = command_journal.operation_id_for("publish", parts)
|
|
121
|
+
images = find_images(content)
|
|
122
|
+
upload_deck = fmt == "html" and (kind == "html_deck" or (kind is None and _declared_deck(content)))
|
|
123
|
+
if getattr(args, "dry_run", False):
|
|
124
|
+
print(json.dumps(payload_summary(content), indent=2, sort_keys=True))
|
|
125
|
+
return
|
|
126
|
+
|
|
127
|
+
client = _client()
|
|
128
|
+
if (images and upload_deck
|
|
129
|
+
and not getattr(args, "no_upload_images", False)):
|
|
130
|
+
draft_options = dict(options)
|
|
131
|
+
if kind is None:
|
|
132
|
+
draft_options["document_kind"] = "html_deck"
|
|
133
|
+
draft_options["deck_contract_version"] = contract or "html-deck/1"
|
|
134
|
+
created = client.publish(
|
|
135
|
+
title, _draft_content(fmt, title, kind), fmt, args.description,
|
|
136
|
+
scope.workspace_id, scope.parent_id, operation_id=op,
|
|
137
|
+
**draft_options)
|
|
138
|
+
document_id = str(created.get("document_id") or "")
|
|
139
|
+
base_version_id = str(created.get("version_id") or "")
|
|
140
|
+
if not document_id or not base_version_id:
|
|
141
|
+
raise RuntimeError("draft create returned no document/version id")
|
|
142
|
+
final_content = _upload_embedded_images(
|
|
143
|
+
client, document_id=document_id, content=content, path=path, op=op)
|
|
144
|
+
result = client.update(
|
|
145
|
+
document_id, final_content, base_version_id, args.description,
|
|
146
|
+
source_format=fmt, operation_id=f"{op}-final"[:199],
|
|
147
|
+
deck_contract_version=draft_options.get("deck_contract_version"))
|
|
148
|
+
result = {
|
|
149
|
+
**result,
|
|
150
|
+
"document_id": document_id,
|
|
151
|
+
"workspace_id": result.get(
|
|
152
|
+
"workspace_id", created.get("workspace_id", scope.workspace_id)),
|
|
153
|
+
"review_url": result.get("review_url") or created.get("review_url", ""),
|
|
154
|
+
}
|
|
155
|
+
else:
|
|
156
|
+
check_publish_size(publish_request_body(
|
|
157
|
+
title, content, fmt, args.description, scope.workspace_id,
|
|
158
|
+
scope.parent_id, operation_id=op, **options))
|
|
159
|
+
result = client.publish(
|
|
160
|
+
title, content, fmt, args.description, scope.workspace_id,
|
|
161
|
+
scope.parent_id, operation_id=op, **options)
|
|
162
|
+
mapping = write_mapping(result, path)
|
|
163
|
+
# The server already told us this title collides with another document in
|
|
164
|
+
# the same session; dropping the hint is how an agent ends up creating
|
|
165
|
+
# eleven near-identical documents without ever noticing.
|
|
166
|
+
duplicate = result.get("duplicate_title_hint") or None
|
|
167
|
+
if getattr(args, "json", False):
|
|
168
|
+
payload = {
|
|
169
|
+
"document_id": mapping["document_id"],
|
|
170
|
+
"version_id": mapping["base_server_version_id"],
|
|
171
|
+
"workspace_id": result.get("workspace_id", scope.workspace_id),
|
|
172
|
+
"review_url": mapping["url"],
|
|
173
|
+
}
|
|
174
|
+
if duplicate:
|
|
175
|
+
payload["duplicate_title_hint"] = duplicate
|
|
176
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
177
|
+
else:
|
|
178
|
+
print(mapping["url"])
|
|
179
|
+
if duplicate:
|
|
180
|
+
print(_duplicate_title_warning(duplicate), file=sys.stderr)
|
|
181
|
+
command_journal.forget("publish", parts)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _duplicate_title_warning(hint: dict) -> str:
|
|
185
|
+
"""Turn the server hint into the sentence an author needs to read.
|
|
186
|
+
|
|
187
|
+
The hint names the document this title collides with; when the server
|
|
188
|
+
suffixed the title it also carries the final title, which is the part that
|
|
189
|
+
explains why the new review is not called what was asked for.
|
|
190
|
+
"""
|
|
191
|
+
final = hint.get("title") or hint.get("final_title") or ""
|
|
192
|
+
existing = hint.get("document_id") or ""
|
|
193
|
+
parts = ["warning: another document in this session already has this title"]
|
|
194
|
+
if existing:
|
|
195
|
+
parts.append(f"({existing})")
|
|
196
|
+
if final:
|
|
197
|
+
parts.append(f"— this one was created as {final!r}")
|
|
198
|
+
return " ".join(parts) + "."
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _source_binding(args: argparse.Namespace) -> tuple[str | None, str | None]:
|
|
202
|
+
source_kind = getattr(args, "source_kind", None)
|
|
203
|
+
source_session_id = getattr(args, "source_session_id", None)
|
|
204
|
+
no_source = getattr(args, "no_source_binding", False)
|
|
205
|
+
if no_source:
|
|
206
|
+
if source_kind is not None or source_session_id is not None:
|
|
207
|
+
raise ValidationError(
|
|
208
|
+
"--no-source-binding cannot be combined with --source-kind or "
|
|
209
|
+
"--source-session-id")
|
|
210
|
+
return None, None
|
|
211
|
+
if (source_kind is None) != (source_session_id is None):
|
|
212
|
+
raise ValidationError(
|
|
213
|
+
"--source-kind and --source-session-id must be supplied together")
|
|
214
|
+
if source_kind is not None:
|
|
215
|
+
source_kind = source_kind.strip()
|
|
216
|
+
source_session_id = source_session_id.strip()
|
|
217
|
+
if not source_kind or not source_session_id:
|
|
218
|
+
raise ValidationError(
|
|
219
|
+
"--source-kind and --source-session-id cannot be empty")
|
|
220
|
+
return source_kind, source_session_id
|
|
221
|
+
# Default-on provenance: agent runtimes inject their session identity into
|
|
222
|
+
# the environment (DSH provides DSH_SESSION_ID).
|
|
223
|
+
session_id = os.environ.get("DSH_SESSION_ID", "").strip()
|
|
224
|
+
return ("dsh", session_id) if session_id else (None, None)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def cmd_open(args: argparse.Namespace) -> None:
|
|
228
|
+
try:
|
|
229
|
+
saved = read_mapping(args.document_id)
|
|
230
|
+
except FileNotFoundError:
|
|
231
|
+
saved = {}
|
|
232
|
+
if saved.get("url"):
|
|
233
|
+
print(canonical_review_url({"review_url": saved["url"]}))
|
|
234
|
+
return
|
|
235
|
+
print(canonical_review_url(_client().status(args.document_id)))
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def cmd_status(args: argparse.Namespace) -> None:
|
|
239
|
+
payload = _client().status(args.document_id)
|
|
240
|
+
if args.json:
|
|
241
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
242
|
+
return
|
|
243
|
+
for key, value in payload.items():
|
|
244
|
+
if key in ACCESS_KEYS:
|
|
245
|
+
continue
|
|
246
|
+
print(f"{key}: {value}")
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def cmd_server_info(args: argparse.Namespace) -> None:
|
|
250
|
+
client = _client()
|
|
251
|
+
payload = {"health": client.health,
|
|
252
|
+
"ready": client.ready,
|
|
253
|
+
"version": client.version_info}[args.kind]()
|
|
254
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def cmd_workspaces(args: argparse.Namespace) -> None:
|
|
258
|
+
payload = _client().workspaces()
|
|
259
|
+
if args.json:
|
|
260
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
261
|
+
return
|
|
262
|
+
for ws in payload.get("workspaces", []):
|
|
263
|
+
print(f"{ws.get('workspace_id')}\t{ws.get('workspace_name')}\t"
|
|
264
|
+
f"[{ws.get('workspace_type')}]\t{ws.get('role')}")
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def cmd_documents(args: argparse.Namespace) -> None:
|
|
268
|
+
payload = _client().dashboard(
|
|
269
|
+
args.workspace_id or "", limit=args.limit or 0,
|
|
270
|
+
offset=args.offset or 0, archived=args.archived)
|
|
271
|
+
if args.json:
|
|
272
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
273
|
+
return
|
|
274
|
+
for doc in payload.get("reviews", []):
|
|
275
|
+
status = doc.get("lifecycle_status") or ""
|
|
276
|
+
print(f"{doc.get('document_id')}\t{doc.get('title')}\t"
|
|
277
|
+
f"[{status}]\t{doc.get('unresolved_count')} open")
|
|
278
|
+
# The server reports has_more/next_offset; printing them turns a silently
|
|
279
|
+
# truncated list into something the user can page through.
|
|
280
|
+
if payload.get("has_more"):
|
|
281
|
+
print(f"more available: rerun with --offset {payload.get('next_offset')}")
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def cmd_document_archive(args: argparse.Namespace) -> None:
|
|
285
|
+
result = _client().archive(args.document_id)
|
|
286
|
+
print(_document_write_line("archived", args.document_id, result, args.json))
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def cmd_document_restore(args: argparse.Namespace) -> None:
|
|
290
|
+
result = _client().restore(args.document_id)
|
|
291
|
+
print(_document_write_line("restored", args.document_id, result, args.json))
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _document_write_line(action: str, document_id: str, result: dict, as_json: bool) -> str:
|
|
295
|
+
if as_json:
|
|
296
|
+
return json.dumps(result, indent=2, sort_keys=True)
|
|
297
|
+
return f"{action} {document_id}"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def cmd_search(args: argparse.Namespace) -> None:
|
|
301
|
+
try:
|
|
302
|
+
payload = search_documents(
|
|
303
|
+
_client(), args.query, workspace_id=args.workspace_id or "",
|
|
304
|
+
limit=args.limit, archived=args.archived,
|
|
305
|
+
include_content=args.include_content)
|
|
306
|
+
except ValidationError as exc:
|
|
307
|
+
raise SystemExit(str(exc)) from exc
|
|
308
|
+
if args.json:
|
|
309
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
310
|
+
return
|
|
311
|
+
for doc in payload.get("matches", []):
|
|
312
|
+
print(f"{doc.get('document_id')}\t{doc.get('title')}\t"
|
|
313
|
+
f"[{doc.get('match_field')}]\t{doc.get('snippet')}")
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def cmd_doctor(args: argparse.Namespace) -> None:
|
|
317
|
+
cfg = _load_config()
|
|
318
|
+
report = doctor_report(
|
|
319
|
+
_client(), _server_url(), _automation_key(cfg),
|
|
320
|
+
os.environ.get("REVISO_WORKSPACE_ID", cfg.get("workspace_id", "")))
|
|
321
|
+
if args.json:
|
|
322
|
+
print(json.dumps(report, indent=2, sort_keys=True))
|
|
323
|
+
return
|
|
324
|
+
print_doctor(report)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def cmd_packet(args: argparse.Namespace) -> None:
|
|
328
|
+
v = "2" if args.v2 else "3"
|
|
329
|
+
packet = _client().packet(args.document_id, args.thread_id, version=v)
|
|
330
|
+
pid = packet.get("document_id", args.document_id)
|
|
331
|
+
path = packet_path(f"pkt_{pid}", "json")
|
|
332
|
+
write_json(path, packet)
|
|
333
|
+
print(str(path))
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _workspace_scope(explicit: str = "", parent_id: str = ""):
|
|
337
|
+
cfg = _load_config()
|
|
338
|
+
key = _automation_key(cfg)
|
|
339
|
+
return resolve_agent_create_scope(
|
|
340
|
+
explicit_workspace_id=explicit, explicit_parent_id=parent_id,
|
|
341
|
+
config=cfg, dsh_workspace_id=dsh_workspace(),
|
|
342
|
+
has_automation_key=bool(key))
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def _add_deck(sub: argparse._SubParsersAction) -> None:
|
|
346
|
+
deck = sub.add_parser("deck", help="Deck authoring helpers.")
|
|
347
|
+
deck_sub = deck.add_subparsers(dest="deck_cmd", required=True)
|
|
348
|
+
validate = deck_sub.add_parser(
|
|
349
|
+
"validate", help="Check a deck against the server contract without publishing.")
|
|
350
|
+
validate.add_argument("file")
|
|
351
|
+
validate.add_argument("--json", action="store_true",
|
|
352
|
+
help="Print the full server result as JSON.")
|
|
353
|
+
validate.set_defaults(func=cmd_deck_validate, client_factory=_client)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _add_basic(sub: argparse._SubParsersAction) -> None:
|
|
357
|
+
auth = sub.add_parser("auth")
|
|
358
|
+
auth.add_argument("action", nargs="?", default="login", choices=["login", "status", "logout"])
|
|
359
|
+
auth.add_argument("--server")
|
|
360
|
+
auth.add_argument("--key")
|
|
361
|
+
auth.add_argument("--no-browser", action="store_true", help="Print the login URL without opening a browser.")
|
|
362
|
+
auth.set_defaults(func=cmd_auth)
|
|
363
|
+
pub = sub.add_parser(
|
|
364
|
+
"publish",
|
|
365
|
+
help="Create a NEW document. Use `document update` to change an existing one.",
|
|
366
|
+
description="Create a new document. This always creates; it never "
|
|
367
|
+
"updates a document with the same title. To modify an "
|
|
368
|
+
"existing document use `reviso document update`.")
|
|
369
|
+
pub.add_argument("file")
|
|
370
|
+
pub.add_argument("--title")
|
|
371
|
+
pub.add_argument("--format", choices=["markdown", "md", "html"])
|
|
372
|
+
pub.add_argument("--description", default="Initial draft")
|
|
373
|
+
pub.add_argument("--workspace-id", default="")
|
|
374
|
+
pub.add_argument("--parent-id", default="")
|
|
375
|
+
pub.add_argument("--kind", choices=["document", "html_deck"])
|
|
376
|
+
pub.add_argument("--deck-contract-version")
|
|
377
|
+
pub.add_argument("--source-kind", help="Provenance channel tag, e.g. 'dsh' for a DeepSeek Harness session.")
|
|
378
|
+
pub.add_argument("--no-source-binding", action="store_true", help="Skip the default session binding when the environment carries an agent session id.")
|
|
379
|
+
pub.add_argument("--source-session-id", help="Session id within the source channel; enables session-scoped reads on the server.")
|
|
380
|
+
pub.add_argument("--json", action="store_true", help="Print document_id, version_id, workspace_id, and review_url as JSON.")
|
|
381
|
+
pub.add_argument("--no-upload-images", action="store_true",
|
|
382
|
+
help="Publish embedded data:image URIs unchanged.")
|
|
383
|
+
pub.add_argument("--dry-run", action="store_true",
|
|
384
|
+
help="Report embedded image counts and bytes without publishing.")
|
|
385
|
+
pub.set_defaults(func=cmd_publish)
|
|
386
|
+
opn = sub.add_parser("open")
|
|
387
|
+
opn.add_argument("document_id")
|
|
388
|
+
opn.set_defaults(func=cmd_open)
|
|
389
|
+
st = sub.add_parser("status")
|
|
390
|
+
st.add_argument("document_id")
|
|
391
|
+
st.add_argument("--json", action="store_true")
|
|
392
|
+
st.set_defaults(func=cmd_status)
|
|
393
|
+
wss = sub.add_parser("workspaces")
|
|
394
|
+
wss.add_argument("--json", action="store_true")
|
|
395
|
+
wss.set_defaults(func=cmd_workspaces)
|
|
396
|
+
docs = sub.add_parser("documents", help="List documents in a workspace.")
|
|
397
|
+
docs.add_argument("--workspace-id", default="")
|
|
398
|
+
docs.add_argument("--limit", type=int, default=0,
|
|
399
|
+
help="Maximum documents to return (server default when omitted).")
|
|
400
|
+
docs.add_argument("--offset", type=int, default=0,
|
|
401
|
+
help="Skip this many documents; page with the next_offset hint.")
|
|
402
|
+
docs.add_argument("--archived", action="store_true",
|
|
403
|
+
help="List the recycle bin instead of active documents.")
|
|
404
|
+
docs.add_argument("--json", action="store_true")
|
|
405
|
+
docs.set_defaults(func=cmd_documents)
|
|
406
|
+
document = sub.add_parser("document", help="Single-document actions.")
|
|
407
|
+
document_sub = document.add_subparsers(dest="document_cmd", required=True)
|
|
408
|
+
archive = document_sub.add_parser("archive", help="Move a document to the recycle bin.")
|
|
409
|
+
archive.add_argument("document_id")
|
|
410
|
+
archive.add_argument("--json", action="store_true")
|
|
411
|
+
archive.set_defaults(func=cmd_document_archive)
|
|
412
|
+
restore = document_sub.add_parser("restore", help="Restore a document from the recycle bin.")
|
|
413
|
+
restore.add_argument("document_id")
|
|
414
|
+
restore.add_argument("--json", action="store_true")
|
|
415
|
+
restore.set_defaults(func=cmd_document_restore)
|
|
416
|
+
search = sub.add_parser("search")
|
|
417
|
+
search.add_argument("query")
|
|
418
|
+
search.add_argument("--workspace-id", default="")
|
|
419
|
+
search.add_argument("--limit", type=int, default=10)
|
|
420
|
+
search.add_argument("--archived", action="store_true")
|
|
421
|
+
search.add_argument("--include-content", action="store_true")
|
|
422
|
+
search.add_argument("--json", action="store_true")
|
|
423
|
+
search.set_defaults(func=cmd_search)
|
|
424
|
+
doctor = sub.add_parser("doctor")
|
|
425
|
+
doctor.add_argument("--json", action="store_true")
|
|
426
|
+
doctor.set_defaults(func=cmd_doctor)
|
|
427
|
+
for name in ("health", "ready", "version"):
|
|
428
|
+
srv = sub.add_parser(name)
|
|
429
|
+
srv.set_defaults(func=cmd_server_info, kind=name)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _add_packet(sub: argparse._SubParsersAction) -> None:
|
|
433
|
+
pkt = sub.add_parser("packet")
|
|
434
|
+
pkt.add_argument("document_id")
|
|
435
|
+
pkt.add_argument("--format", choices=["json"], default="json")
|
|
436
|
+
pkt.add_argument("--thread-id", action="append")
|
|
437
|
+
pkt.add_argument("--v2", action="store_true",
|
|
438
|
+
help="Use legacy packet v2 with sections")
|
|
439
|
+
pkt.set_defaults(func=cmd_packet)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def _add_review_io(sub: argparse._SubParsersAction) -> None:
|
|
443
|
+
exp = sub.add_parser("export")
|
|
444
|
+
exp.add_argument("document_id")
|
|
445
|
+
exp.add_argument("--output", default="")
|
|
446
|
+
exp.set_defaults(func=cmd_export)
|
|
447
|
+
imp = sub.add_parser("import")
|
|
448
|
+
imp.add_argument("file")
|
|
449
|
+
imp.add_argument("--workspace-id", default="")
|
|
450
|
+
imp.add_argument("--parent-id", default="")
|
|
451
|
+
imp.set_defaults(func=cmd_import)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def cmd_export(args: argparse.Namespace) -> None:
|
|
455
|
+
bundle = _client().export_review(args.document_id)
|
|
456
|
+
if args.output:
|
|
457
|
+
write_json(Path(args.output), bundle)
|
|
458
|
+
print(args.output)
|
|
459
|
+
return
|
|
460
|
+
print(json.dumps(bundle, indent=2, sort_keys=True))
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def cmd_import(args: argparse.Namespace) -> None:
|
|
464
|
+
bundle = read_json(Path(args.file))
|
|
465
|
+
scope = _workspace_scope(args.workspace_id or "", args.parent_id or "")
|
|
466
|
+
result = _client().import_review(
|
|
467
|
+
bundle, scope.workspace_id, scope.parent_id)
|
|
468
|
+
print(json.dumps(result, indent=2, sort_keys=True))
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
472
|
+
parser = argparse.ArgumentParser(prog="reviso")
|
|
473
|
+
sub = parser.add_subparsers(dest="cmd", required=True)
|
|
474
|
+
_add_basic(sub)
|
|
475
|
+
_add_packet(sub)
|
|
476
|
+
_add_review_io(sub)
|
|
477
|
+
add_guest_comment_commands(sub, _client)
|
|
478
|
+
add_invite_commands(sub, _client)
|
|
479
|
+
add_version_commands(sub, _client)
|
|
480
|
+
_add_deck(sub)
|
|
481
|
+
return parser
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def main(argv: list[str] | None = None) -> None:
|
|
485
|
+
parser = build_parser()
|
|
486
|
+
args = parser.parse_args(argv)
|
|
487
|
+
try:
|
|
488
|
+
args.func(args)
|
|
489
|
+
except ValidationError as exc:
|
|
490
|
+
raise SystemExit(str(exc)) from exc
|