apheris-foundry-cli 2.3.0__tar.gz → 2.4.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.
Files changed (68) hide show
  1. {apheris_foundry_cli-2.3.0/src/apheris_foundry_cli.egg-info → apheris_foundry_cli-2.4.0}/PKG-INFO +2 -1
  2. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/README.md +1 -0
  3. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/pyproject.toml +1 -1
  4. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0/src/apheris_foundry_cli.egg-info}/PKG-INFO +2 -1
  5. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apheris_foundry_cli.egg-info/SOURCES.txt +2 -0
  6. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/docs.py +64 -7
  7. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/foundry.py +67 -1
  8. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/auth.py +1 -29
  9. apheris_foundry_cli-2.4.0/src/apherisfold_cli/core/browser.py +31 -0
  10. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/main.py +16 -1
  11. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/skills/apheris-foundry-hub/SKILL.md +5 -0
  12. apheris_foundry_cli-2.4.0/src/apherisfold_cli/version.py +1 -0
  13. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_auth.py +0 -32
  14. apheris_foundry_cli-2.4.0/tests/test_browser.py +63 -0
  15. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_cli.py +138 -0
  16. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_docs.py +88 -0
  17. apheris_foundry_cli-2.3.0/src/apherisfold_cli/version.py +0 -1
  18. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/LICENSE +0 -0
  19. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/setup.cfg +0 -0
  20. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apheris_foundry_cli.egg-info/dependency_links.txt +0 -0
  21. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apheris_foundry_cli.egg-info/entry_points.txt +0 -0
  22. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apheris_foundry_cli.egg-info/requires.txt +0 -0
  23. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apheris_foundry_cli.egg-info/top_level.txt +0 -0
  24. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/__init__.py +0 -0
  25. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/__init__.py +0 -0
  26. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/compounds.py +0 -0
  27. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/login.py +0 -0
  28. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/settings.py +0 -0
  29. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/skills.py +0 -0
  30. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/commands/weights.py +0 -0
  31. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/__init__.py +0 -0
  32. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/config.py +0 -0
  33. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/context.py +0 -0
  34. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/documents.py +0 -0
  35. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/errors.py +0 -0
  36. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/hub_requests.py +0 -0
  37. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/input_archive.py +0 -0
  38. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/io.py +0 -0
  39. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/limits.py +0 -0
  40. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/login_profiles.py +0 -0
  41. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/msa.py +0 -0
  42. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/pubchem.py +0 -0
  43. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/render.py +0 -0
  44. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/result_artifacts.py +0 -0
  45. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/core/transient.py +0 -0
  46. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/src/apherisfold_cli/handlers.py +0 -0
  47. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_auth_lifecycle.py +0 -0
  48. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_benchmark_examples.py +0 -0
  49. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_config.py +0 -0
  50. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_documents.py +0 -0
  51. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_dry_run_guard.py +0 -0
  52. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_foundry_helpers.py +0 -0
  53. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_foundry_warnings.py +0 -0
  54. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_handlers.py +0 -0
  55. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_hub_requests.py +0 -0
  56. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_input_archive.py +0 -0
  57. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_io.py +0 -0
  58. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_jobs_metadata.py +0 -0
  59. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_jobs_update.py +0 -0
  60. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_login_callback.py +0 -0
  61. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_main.py +0 -0
  62. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_model_discovery.py +0 -0
  63. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_msa.py +0 -0
  64. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_pubchem.py +0 -0
  65. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_render.py +0 -0
  66. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_result_artifacts.py +0 -0
  67. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_skills.py +0 -0
  68. {apheris_foundry_cli-2.3.0 → apheris_foundry_cli-2.4.0}/tests/test_weights.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apheris-foundry-cli
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Command-line interface for Apheris Foundry workflows.
5
5
  Author: Apheris
6
6
  License-Expression: LicenseRef-Apheris-Foundry-Software-License
@@ -351,6 +351,7 @@ the metadata change notification.
351
351
  | ------- | ----------- |
352
352
  | `apheris-foundry jobs list [--workflow <id>]` | List submitted jobs using server-side filters and bounded hydration |
353
353
  | `apheris-foundry jobs get --id <job-id>` | Inspect a job and its artifacts |
354
+ | `apheris-foundry jobs get --id <job-id> --web` | Print the job's Hub URL; add `--auto` to open it in the default browser |
354
355
  | `apheris-foundry jobs update --id <job-id> [--name <name>] [--tag <tag> ... \| --clear-tags]` | Edit metadata; omitted fields stay unchanged, tags replace all existing tags, and `--name ""` / `--clear-tags` clear fields |
355
356
  | `apheris-foundry jobs logs --id <job-id>` | Print logs for a job |
356
357
  | `apheris-foundry jobs error --id <job-id>` | Print the saved error for a failed job |
@@ -325,6 +325,7 @@ the metadata change notification.
325
325
  | ------- | ----------- |
326
326
  | `apheris-foundry jobs list [--workflow <id>]` | List submitted jobs using server-side filters and bounded hydration |
327
327
  | `apheris-foundry jobs get --id <job-id>` | Inspect a job and its artifacts |
328
+ | `apheris-foundry jobs get --id <job-id> --web` | Print the job's Hub URL; add `--auto` to open it in the default browser |
328
329
  | `apheris-foundry jobs update --id <job-id> [--name <name>] [--tag <tag> ... \| --clear-tags]` | Edit metadata; omitted fields stay unchanged, tags replace all existing tags, and `--name ""` / `--clear-tags` clear fields |
329
330
  | `apheris-foundry jobs logs --id <job-id>` | Print logs for a job |
330
331
  | `apheris-foundry jobs error --id <job-id>` | Print the saved error for a failed job |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "apheris-foundry-cli"
7
- version = "2.3.0"
7
+ version = "2.4.0"
8
8
  description = "Command-line interface for Apheris Foundry workflows."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apheris-foundry-cli
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Command-line interface for Apheris Foundry workflows.
5
5
  Author: Apheris
6
6
  License-Expression: LicenseRef-Apheris-Foundry-Software-License
@@ -351,6 +351,7 @@ the metadata change notification.
351
351
  | ------- | ----------- |
352
352
  | `apheris-foundry jobs list [--workflow <id>]` | List submitted jobs using server-side filters and bounded hydration |
353
353
  | `apheris-foundry jobs get --id <job-id>` | Inspect a job and its artifacts |
354
+ | `apheris-foundry jobs get --id <job-id> --web` | Print the job's Hub URL; add `--auto` to open it in the default browser |
354
355
  | `apheris-foundry jobs update --id <job-id> [--name <name>] [--tag <tag> ... \| --clear-tags]` | Edit metadata; omitted fields stay unchanged, tags replace all existing tags, and `--name ""` / `--clear-tags` clear fields |
355
356
  | `apheris-foundry jobs logs --id <job-id>` | Print logs for a job |
356
357
  | `apheris-foundry jobs error --id <job-id>` | Print the saved error for a failed job |
@@ -21,6 +21,7 @@ src/apherisfold_cli/commands/skills.py
21
21
  src/apherisfold_cli/commands/weights.py
22
22
  src/apherisfold_cli/core/__init__.py
23
23
  src/apherisfold_cli/core/auth.py
24
+ src/apherisfold_cli/core/browser.py
24
25
  src/apherisfold_cli/core/config.py
25
26
  src/apherisfold_cli/core/context.py
26
27
  src/apherisfold_cli/core/documents.py
@@ -39,6 +40,7 @@ src/apherisfold_cli/skills/apheris-foundry-hub/SKILL.md
39
40
  tests/test_auth.py
40
41
  tests/test_auth_lifecycle.py
41
42
  tests/test_benchmark_examples.py
43
+ tests/test_browser.py
42
44
  tests/test_cli.py
43
45
  tests/test_config.py
44
46
  tests/test_docs.py
@@ -6,6 +6,7 @@ from typing import Annotated, Any
6
6
 
7
7
  import typer
8
8
  from rich import box
9
+ from rich.console import Group
9
10
  from rich.markdown import Markdown
10
11
  from rich.table import Table
11
12
  from rich.text import Text
@@ -23,7 +24,7 @@ def _invalid() -> CLIError:
23
24
  )
24
25
 
25
26
 
26
- def _pages(entries: Any, depth: int = 0) -> list[dict[str, str]]:
27
+ def _pages(entries: Any, depth: int = 0, sections: tuple[str, ...] = ()) -> list[dict[str, Any]]:
27
28
  if not isinstance(entries, list) or not entries or depth > 20:
28
29
  raise _invalid()
29
30
  pages = []
@@ -39,30 +40,83 @@ def _pages(entries: Any, depth: int = 0) -> list[dict[str, str]]:
39
40
  or any(char in path for char in "\\?#:%")
40
41
  ):
41
42
  raise _invalid()
42
- pages.append({"title": entry["title"], "path": path})
43
+ pages.append(
44
+ {"title": entry["title"], "path": path, "sections": sections, "draft": entry.get("draft") is True}
45
+ )
43
46
  else:
44
- pages.extend(_pages(entry.get("children"), depth + 1))
47
+ pages.extend(_pages(entry.get("children"), depth + 1, (*sections, entry["title"])))
45
48
  return pages
46
49
 
47
50
 
48
- def _index() -> tuple[dict[str, Any], list[dict[str, str]]]:
51
+ def _index() -> tuple[dict[str, Any], list[dict[str, Any]]]:
49
52
  payload = get_hub_documentation_index()
50
53
  if not isinstance(payload.get("hubVersion"), str):
51
54
  raise _invalid()
52
55
  return payload, _pages(payload.get("navigation"))
53
56
 
54
57
 
58
+ def _release_sections(entries: list[Any], sections: tuple[str, ...] = ()) -> list[tuple[str, ...]]:
59
+ """Match the Hub UI: a release is a section whose pages all live under releases/."""
60
+ releases = []
61
+ for entry in entries:
62
+ children = entry.get("children") or []
63
+ if children and all(str(child.get("path") or "").startswith("releases/") for child in children):
64
+ releases.append((*sections, entry["title"]))
65
+ elif children:
66
+ releases.extend(_release_sections(children, (*sections, entry["title"])))
67
+ return releases
68
+
69
+
70
+ def _matches_release(sections: tuple[str, ...], release: str) -> bool:
71
+ return bool(sections) and (sections[-1] == release or sections[-1].endswith(f" {release}"))
72
+
73
+
74
+ def _module_version(version: str) -> str:
75
+ """A Go pseudo-version names an untagged commit; show that commit instead."""
76
+ match = re.fullmatch(r"v\d+\.\d+\.\d+-(?:.+\.)?\d{14}-([0-9a-f]{12})", version)
77
+ return f"commit {match.group(1)[:7]}" if match else version
78
+
79
+
55
80
  @app.command("list", help="List the private documents available on the selected Hub.")
56
81
  def list_docs(
82
+ release: Annotated[
83
+ str | None,
84
+ typer.Option("--release", help="Show only the documents of one release, for example 1.0.0."),
85
+ ] = None,
57
86
  json_output: Annotated[bool, typer.Option("--json", help="Return the original navigation as JSON.")] = False,
58
87
  ) -> None:
59
88
  payload, pages = _index()
89
+ releases = _release_sections(payload["navigation"])
90
+ if release is not None:
91
+ pages = [page for page in pages if page["sections"] in releases and _matches_release(page["sections"], release)]
92
+ if not pages:
93
+ available = ", ".join(sections[-1] for sections in releases) or "none"
94
+ raise CLIError(
95
+ code=EXIT_USAGE,
96
+ category="usage",
97
+ message=f"This Hub has no release {release!r}. Available releases: {available}.",
98
+ task="docs.list",
99
+ )
60
100
  if json_output:
61
101
  run_simple_listing(payload=payload)
62
102
  return
63
- table = Table("Document", "Path", box=box.SIMPLE_HEAD)
103
+ caption = f"Hub {payload['hubVersion']}"
104
+ if isinstance(payload.get("toolkitVersion"), str) and payload["toolkitVersion"]:
105
+ caption += f" · foundry-toolkit {_module_version(payload['toolkitVersion'])}"
106
+ table = Table(box=box.SIMPLE_HEAD, caption=caption, caption_justify="left")
107
+ table.add_column("Section")
108
+ table.add_column("Document")
109
+ # Paths are copied into 'docs show', so narrow terminals wrap the other columns.
110
+ table.add_column("Path", no_wrap=True, min_width=max((len(page["path"]) for page in pages), default=4))
111
+ latest = releases[0] if releases else None
64
112
  for page in pages:
65
- table.add_row(Text(page["title"]), Text(page["path"]))
113
+ section = " › ".join(page["sections"])
114
+ if page["sections"] and page["sections"] == latest:
115
+ section += " (latest)"
116
+ title = Text(page["title"])
117
+ if page["draft"]:
118
+ title.append(" Draft", style="yellow")
119
+ table.add_row(Text(section), title, Text(page["path"]))
66
120
  run_simple_listing(payload=payload, renderable_output=table)
67
121
 
68
122
 
@@ -102,4 +156,7 @@ def show_doc(
102
156
  run_simple_listing(payload=payload)
103
157
  else:
104
158
  body = re.sub(r"\A---\r?\n[\s\S]*?\r?\n---(?:\r?\n|\Z)", "", content, count=1)
105
- run_simple_listing(payload=payload, renderable_output=Markdown(body))
159
+ renderable: Any = Markdown(body)
160
+ if payload.get("draft") is True:
161
+ renderable = Group(Text("Draft: unreviewed, may change before release.", style="yellow"), renderable)
162
+ run_simple_listing(payload=payload, renderable_output=renderable)
@@ -9,6 +9,7 @@ from collections.abc import Iterable
9
9
  from io import BytesIO
10
10
  from pathlib import Path
11
11
  from typing import Any
12
+ from urllib.parse import quote, urlsplit
12
13
 
13
14
  import typer
14
15
  from rich import box
@@ -18,6 +19,8 @@ from rich.table import Table
18
19
  from rich.text import Text
19
20
  from rich.tree import Tree
20
21
 
22
+ from apherisfold_cli.core.auth import load_runtime_config
23
+ from apherisfold_cli.core.browser import open_browser
21
24
  from apherisfold_cli.core.errors import EXIT_INPUT_DATA, EXIT_INTERNAL, EXIT_PRECONDITION, EXIT_USAGE, CLIError
22
25
  from apherisfold_cli.core.hub_requests import (
23
26
  cancel_foundry_run,
@@ -1059,7 +1062,70 @@ def foundry_workflow_graph(workflow: str, *, json_output: bool, html_output: Pat
1059
1062
  )
1060
1063
 
1061
1064
 
1062
- def foundry_get(run_id: str, *, artifact_id: str | None, json_output: bool) -> None:
1065
+ def _show_job_url(run_id: str, *, auto_open_browser: bool) -> None:
1066
+ if not run_id.strip() or run_id in {".", ".."}:
1067
+ raise CLIError(code=EXIT_USAGE, category="usage", message="--id must be a job identifier.", task="foundry.get")
1068
+
1069
+ config = load_runtime_config()
1070
+ if config is None:
1071
+ raise CLIError(
1072
+ code=EXIT_PRECONDITION,
1073
+ category="precondition",
1074
+ message="No Hub runtime configuration found. Run 'apheris-foundry login' first.",
1075
+ task="foundry.get",
1076
+ )
1077
+ hub_url = config.hub_url.rstrip("/")
1078
+ try:
1079
+ parsed = urlsplit(hub_url)
1080
+ valid_url = (
1081
+ parsed.scheme in {"http", "https"}
1082
+ and bool(parsed.hostname)
1083
+ and parsed.port != 0
1084
+ and parsed.username is None
1085
+ and parsed.password is None
1086
+ and "?" not in hub_url
1087
+ and "#" not in hub_url
1088
+ and not re.search(r"[\\\x00-\x20\x7f]", hub_url)
1089
+ )
1090
+ except ValueError:
1091
+ valid_url = False
1092
+ if not valid_url:
1093
+ raise CLIError(
1094
+ code=EXIT_PRECONDITION,
1095
+ category="precondition",
1096
+ message="Invalid Hub URL. Run 'apheris-foundry login' with an HTTP(S) Hub URL without credentials, query, or fragment.",
1097
+ task="foundry.get",
1098
+ )
1099
+
1100
+ url = f"{hub_url}/jobs/{quote(run_id, safe='')}"
1101
+ if not auto_open_browser:
1102
+ typer.echo(url)
1103
+ return
1104
+ if not open_browser(url):
1105
+ raise CLIError(
1106
+ code=EXIT_PRECONDITION,
1107
+ category="precondition",
1108
+ message=f"Could not open the default browser. Open this URL manually: {url}",
1109
+ task="foundry.get",
1110
+ )
1111
+ typer.echo(f"Opening {url}")
1112
+
1113
+
1114
+ def foundry_get(
1115
+ run_id: str, *, artifact_id: str | None, json_output: bool, web: bool = False, auto_open_browser: bool = False
1116
+ ) -> None:
1117
+ if auto_open_browser and not web:
1118
+ raise CLIError(code=EXIT_USAGE, category="usage", message="--auto requires --web.", task="foundry.get")
1119
+ if web:
1120
+ if json_output or artifact_id is not None:
1121
+ raise CLIError(
1122
+ code=EXIT_USAGE,
1123
+ category="usage",
1124
+ message="--web cannot be combined with --json or --artifact-id.",
1125
+ task="foundry.get",
1126
+ )
1127
+ _show_job_url(run_id, auto_open_browser=auto_open_browser)
1128
+ return
1063
1129
  run = get_foundry_run(run_id)
1064
1130
  if artifact_id:
1065
1131
  artifact = _resolve_artifact(run, artifact_id)
@@ -8,22 +8,20 @@ import json
8
8
  import os
9
9
  import queue
10
10
  import secrets
11
- import shutil
12
11
  import ssl
13
- import subprocess
14
12
  import sys
15
13
  import threading
16
14
  import time
17
15
  import urllib.error
18
16
  import urllib.parse
19
17
  import urllib.request
20
- import webbrowser
21
18
  from dataclasses import asdict, dataclass
22
19
  from http.client import IncompleteRead
23
20
  from http.server import BaseHTTPRequestHandler, HTTPServer
24
21
  from pathlib import Path
25
22
  from typing import Any, cast
26
23
 
24
+ from .browser import open_browser as _browser_open
27
25
  from .errors import (
28
26
  EXIT_INPUT_DATA,
29
27
  EXIT_INTERNAL,
@@ -1050,32 +1048,6 @@ def _pkce_code_challenge(code_verifier: str) -> str:
1050
1048
  return base64.urlsafe_b64encode(digest).decode("utf-8").rstrip("=")
1051
1049
 
1052
1050
 
1053
- def _browser_open(url: str) -> bool:
1054
- browser_commands = (
1055
- ["xdg-open", url],
1056
- ["gio", "open", url],
1057
- ["open", url],
1058
- )
1059
- for command in browser_commands:
1060
- if shutil.which(command[0]) is None:
1061
- continue
1062
- try:
1063
- subprocess.Popen(
1064
- command,
1065
- stdout=subprocess.DEVNULL,
1066
- stderr=subprocess.DEVNULL,
1067
- stdin=subprocess.DEVNULL,
1068
- start_new_session=True,
1069
- )
1070
- return True
1071
- except OSError:
1072
- continue
1073
- try:
1074
- return bool(webbrowser.open(url))
1075
- except webbrowser.Error:
1076
- return False
1077
-
1078
-
1079
1051
  def _browser_auto_open_enabled() -> bool:
1080
1052
  open_raw = (os.getenv("APHERIS_FOUNDRY_OPEN_BROWSER") or os.getenv("APHERISFOLD_OPEN_BROWSER", "")).strip().lower()
1081
1053
  if open_raw in {"1", "true", "yes", "on"}:
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ import shutil
4
+ import subprocess
5
+ import webbrowser
6
+
7
+
8
+ def open_browser(url: str) -> bool:
9
+ browser_commands = (
10
+ ["xdg-open", url],
11
+ ["gio", "open", url],
12
+ ["open", url],
13
+ )
14
+ for command in browser_commands:
15
+ if shutil.which(command[0]) is None:
16
+ continue
17
+ try:
18
+ subprocess.Popen(
19
+ command,
20
+ stdout=subprocess.DEVNULL,
21
+ stderr=subprocess.DEVNULL,
22
+ stdin=subprocess.DEVNULL,
23
+ start_new_session=True,
24
+ )
25
+ return True
26
+ except OSError:
27
+ continue
28
+ try:
29
+ return bool(webbrowser.open(url))
30
+ except (webbrowser.Error, OSError):
31
+ return False
@@ -243,8 +243,15 @@ def get_cmd(
243
243
  run_id: Annotated[str, typer.Option("--id", help="Foundry job identifier.")],
244
244
  artifact_id: Annotated[str | None, typer.Option("--artifact-id", help="Preview one file ID from this job.")] = None,
245
245
  json_output: Annotated[bool, typer.Option("--json", help="Render as JSON.")] = False,
246
+ web: Annotated[
247
+ bool,
248
+ typer.Option("--web", help="Print the job's Hub URL. Cannot be combined with --json or --artifact-id."),
249
+ ] = False,
250
+ auto_open_browser: Annotated[
251
+ bool, typer.Option("--auto", help="Open the job URL in the default browser automatically. Requires --web.")
252
+ ] = False,
246
253
  ) -> None:
247
- foundry_get(run_id, artifact_id=artifact_id, json_output=json_output)
254
+ foundry_get(run_id, artifact_id=artifact_id, json_output=json_output, web=web, auto_open_browser=auto_open_browser)
248
255
 
249
256
 
250
257
  @jobs_app.command(
@@ -516,7 +523,12 @@ def workflows_graph_cmd(
516
523
  def workflows_docs_cmd(
517
524
  workflow_id: Annotated[str, typer.Option("--workflow", help="Workflow ID.")],
518
525
  json_output: Annotated[bool, typer.Option("--json", help="Render as JSON.")] = False,
526
+ raw: Annotated[
527
+ bool, typer.Option("--raw", help="Write the exact README Markdown to stdout for offline reading.")
528
+ ] = False,
519
529
  ) -> None:
530
+ if raw and json_output:
531
+ raise typer.BadParameter("Use either --raw or --json.")
520
532
  payload = get_foundry_workflow_docs(workflow_id)
521
533
  content = payload.get("content")
522
534
  if (
@@ -532,6 +544,9 @@ def workflows_docs_cmd(
532
544
  message="Hub returned invalid workflow docs.",
533
545
  task="workflows.docs",
534
546
  )
547
+ if raw:
548
+ typer.echo(content, nl=False)
549
+ return
535
550
  if json_output:
536
551
  run_simple_listing(payload=payload)
537
552
  return
@@ -159,6 +159,11 @@ Listing defaults to 30 rows. JSON `total` counts all matches; `incomplete` means
159
159
  fewer rows were returned. Narrow the search before using `--limit -1` to fetch
160
160
  all matches. Once a job is identified, use `jobs get --id <id>`.
161
161
 
162
+ To give the user the job's Hub page, run `jobs get --id <id> --web`; it prints
163
+ the URL without fetching the job. Add `--auto` only when the user asks to open
164
+ it in their browser, which uses its own Hub login. `--web` cannot be combined
165
+ with `--json` or `--artifact-id`.
166
+
162
167
  ### Submit and monitor prepared inputs
163
168
 
164
169
  If the relevant workflow skill is already installed for this Hub/version, read
@@ -0,0 +1 @@
1
+ __version__ = "2.4.0"
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import io
4
- import subprocess
5
4
  import urllib.error
6
5
  from pathlib import Path
7
6
 
@@ -13,7 +12,6 @@ from apherisfold_cli.core.auth import (
13
12
  RuntimeAuthConfig,
14
13
  _auth0_logout_url,
15
14
  _browser_auto_open_enabled,
16
- _browser_open,
17
15
  _oidc_logout_url,
18
16
  build_authorization_parameters,
19
17
  build_token_exchange_form,
@@ -511,36 +509,6 @@ def test_perform_logout_forgerock_is_local_only_even_in_global_mode(monkeypatch,
511
509
  assert result.provider_logout_attempted is False
512
510
 
513
511
 
514
- def test_browser_open_prefers_detached_subprocess(monkeypatch) -> None:
515
- captured: dict[str, object] = {}
516
-
517
- monkeypatch.setattr(
518
- "apherisfold_cli.core.auth.shutil.which", lambda name: "/usr/bin/" + name if name == "xdg-open" else None
519
- )
520
-
521
- def fake_popen(command, **kwargs):
522
- captured["command"] = command
523
- captured["kwargs"] = kwargs
524
- return object()
525
-
526
- monkeypatch.setattr("apherisfold_cli.core.auth.subprocess.Popen", fake_popen)
527
-
528
- assert _browser_open("https://example.com/login") is True
529
- assert captured["command"] == ["xdg-open", "https://example.com/login"]
530
- kwargs = captured["kwargs"]
531
- assert kwargs["stdout"] is subprocess.DEVNULL
532
- assert kwargs["stderr"] is subprocess.DEVNULL
533
- assert kwargs["stdin"] is subprocess.DEVNULL
534
- assert kwargs["start_new_session"] is True
535
-
536
-
537
- def test_browser_open_falls_back_to_webbrowser(monkeypatch) -> None:
538
- monkeypatch.setattr("apherisfold_cli.core.auth.shutil.which", lambda _name: None)
539
- monkeypatch.setattr("apherisfold_cli.core.auth.webbrowser.open", lambda url: url == "https://example.com/login")
540
-
541
- assert _browser_open("https://example.com/login") is True
542
-
543
-
544
512
  def test_browser_auto_open_can_be_disabled(monkeypatch) -> None:
545
513
  monkeypatch.setenv("APHERISFOLD_NO_BROWSER", "1")
546
514
  assert _browser_auto_open_enabled() is False
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+ import webbrowser
5
+
6
+ import pytest
7
+
8
+ from apherisfold_cli.core.browser import open_browser
9
+
10
+
11
+ def test_browser_open_prefers_detached_subprocess(monkeypatch) -> None:
12
+ captured: dict[str, object] = {}
13
+
14
+ monkeypatch.setattr(
15
+ "apherisfold_cli.core.browser.shutil.which", lambda name: "/usr/bin/" + name if name == "xdg-open" else None
16
+ )
17
+
18
+ def fake_popen(command, **kwargs):
19
+ captured["command"] = command
20
+ captured["kwargs"] = kwargs
21
+ return object()
22
+
23
+ monkeypatch.setattr("apherisfold_cli.core.browser.subprocess.Popen", fake_popen)
24
+
25
+ assert open_browser("https://example.com/login") is True
26
+ assert captured["command"] == ["xdg-open", "https://example.com/login"]
27
+ kwargs = captured["kwargs"]
28
+ assert kwargs["stdout"] is subprocess.DEVNULL
29
+ assert kwargs["stderr"] is subprocess.DEVNULL
30
+ assert kwargs["stdin"] is subprocess.DEVNULL
31
+ assert kwargs["start_new_session"] is True
32
+
33
+
34
+ def test_browser_open_falls_back_to_webbrowser(monkeypatch) -> None:
35
+ monkeypatch.setattr("apherisfold_cli.core.browser.shutil.which", lambda _name: None)
36
+ monkeypatch.setattr("apherisfold_cli.core.browser.webbrowser.open", lambda url: url == "https://example.com/login")
37
+
38
+ assert open_browser("https://example.com/login") is True
39
+
40
+
41
+ @pytest.mark.parametrize("error", [webbrowser.Error("unavailable"), OSError("unavailable")])
42
+ def test_browser_open_handles_fallback_errors(monkeypatch, error) -> None:
43
+ monkeypatch.setattr("apherisfold_cli.core.browser.shutil.which", lambda _name: None)
44
+
45
+ def fail_open(_url):
46
+ raise error
47
+
48
+ monkeypatch.setattr("apherisfold_cli.core.browser.webbrowser.open", fail_open)
49
+ assert open_browser("https://example.com/job") is False
50
+
51
+
52
+ def test_browser_open_falls_back_after_launcher_errors(monkeypatch) -> None:
53
+ monkeypatch.setattr("apherisfold_cli.core.browser.shutil.which", lambda name: "/usr/bin/" + name)
54
+ attempts = []
55
+
56
+ def fail_launch(command, **_kwargs):
57
+ attempts.append(command[0])
58
+ raise OSError("unavailable")
59
+
60
+ monkeypatch.setattr("apherisfold_cli.core.browser.subprocess.Popen", fail_launch)
61
+ monkeypatch.setattr("apherisfold_cli.core.browser.webbrowser.open", lambda _url: False)
62
+ assert open_browser("https://example.com/job") is False
63
+ assert attempts == ["xdg-open", "gio", "open"]
@@ -637,6 +637,17 @@ def test_foundry_workflows_docs_json_output(monkeypatch, workflow_docs_markdown)
637
637
  assert json.loads(result.stdout) == payload
638
638
 
639
639
 
640
+ def test_foundry_workflows_docs_raw_exports_exact_readme(monkeypatch, workflow_docs_markdown) -> None:
641
+ payload = _workflow_docs_payload(workflow_docs_markdown)
642
+ monkeypatch.setattr("apherisfold_cli.main.get_foundry_workflow_docs", lambda workflow_id: payload)
643
+ result = runner.invoke(app, ["workflows", "docs", "--workflow", "predict", "--raw"])
644
+
645
+ assert result.exit_code == 0
646
+ assert result.stdout_bytes == workflow_docs_markdown.encode()
647
+ both = runner.invoke(app, ["workflows", "docs", "--workflow", "predict", "--raw", "--json"])
648
+ assert both.exit_code == 2
649
+
650
+
640
651
  @pytest.mark.parametrize(
641
652
  "payload",
642
653
  [
@@ -1654,6 +1665,133 @@ def test_login_status_verbose_explains_mismatched_session() -> None:
1654
1665
  # ---------------------------------------------------------------------------
1655
1666
 
1656
1667
 
1668
+ @pytest.mark.parametrize("hub_url", ["https://hub.example", "https://hub.example/", "http://localhost:8080/hub/"])
1669
+ @pytest.mark.parametrize("auto", [False, True])
1670
+ def test_foundry_get_web_uses_configured_hub_without_api_calls(hub_api_fixture, hub_url, auto) -> None:
1671
+ url = hub_url.rstrip("/") + "/jobs/foundry_3c80557bffb50f6c"
1672
+ with (
1673
+ patch("apherisfold_cli.commands.foundry.load_runtime_config", return_value=SimpleNamespace(hub_url=hub_url)),
1674
+ patch("apherisfold_cli.commands.foundry.open_browser", return_value=True) as browser,
1675
+ ):
1676
+ result = runner.invoke(
1677
+ app, ["jobs", "get", "--id", "foundry_3c80557bffb50f6c", "--web", *(["--auto"] if auto else [])]
1678
+ )
1679
+ assert result.exit_code == 0, result.exception
1680
+ if auto:
1681
+ browser.assert_called_once_with(url)
1682
+ assert url in result.stdout
1683
+ else:
1684
+ browser.assert_not_called()
1685
+ assert result.stdout == url + "\n"
1686
+ assert not any(hub_api_fixture.values())
1687
+
1688
+
1689
+ def test_foundry_get_web_encodes_job_id(hub_api_fixture) -> None:
1690
+ with (
1691
+ patch(
1692
+ "apherisfold_cli.commands.foundry.load_runtime_config",
1693
+ return_value=SimpleNamespace(hub_url="https://hub.example"),
1694
+ ),
1695
+ patch("apherisfold_cli.commands.foundry.open_browser", return_value=True) as browser,
1696
+ ):
1697
+ result = runner.invoke(app, ["jobs", "get", "--id", "//other.example/a?b#c%20", "--web", "--auto"])
1698
+ assert result.exit_code == 0, result.exception
1699
+ browser.assert_called_once_with("https://hub.example/jobs/%2F%2Fother.example%2Fa%3Fb%23c%2520")
1700
+
1701
+
1702
+ @pytest.mark.parametrize("extra", [["--json"], ["--artifact-id", "trace"], ["--artifact-id", ""]])
1703
+ def test_foundry_get_web_rejects_conflicting_options(hub_api_fixture, extra) -> None:
1704
+ with patch("apherisfold_cli.commands.foundry.open_browser") as browser:
1705
+ result = runner.invoke(app, ["jobs", "get", "--id", "foundry_test_001", "--web", *extra])
1706
+ assert isinstance(result.exception, CLIError)
1707
+ assert result.exception.code == 2
1708
+ assert "--web cannot be combined" in result.exception.message
1709
+ browser.assert_not_called()
1710
+ assert not any(hub_api_fixture.values())
1711
+
1712
+
1713
+ @pytest.mark.parametrize("run_id", ["", " ", ".", ".."])
1714
+ def test_foundry_get_web_rejects_empty_and_dot_ids(hub_api_fixture, run_id) -> None:
1715
+ with patch("apherisfold_cli.commands.foundry.open_browser") as browser:
1716
+ result = runner.invoke(app, ["jobs", "get", "--id", run_id, "--web"])
1717
+ assert isinstance(result.exception, CLIError)
1718
+ assert result.exception.code == 2
1719
+ browser.assert_not_called()
1720
+ assert not any(hub_api_fixture.values())
1721
+
1722
+
1723
+ @pytest.mark.parametrize(
1724
+ "hub_url",
1725
+ [
1726
+ None,
1727
+ "",
1728
+ "hub.example",
1729
+ "file:///tmp/job",
1730
+ "https://",
1731
+ "https://[invalid",
1732
+ "https://hub.example:invalid",
1733
+ "https://user:secret@hub.example",
1734
+ "https://hub.example?token=secret",
1735
+ "https://hub.example#secret",
1736
+ "https://hub.example?",
1737
+ "https://hub.example#",
1738
+ "https://hub.example\\other",
1739
+ "https://hub.example\nother",
1740
+ ],
1741
+ )
1742
+ def test_foundry_get_web_requires_valid_hub_configuration(hub_api_fixture, hub_url) -> None:
1743
+ config = SimpleNamespace(hub_url=hub_url) if hub_url is not None else None
1744
+ with (
1745
+ patch("apherisfold_cli.commands.foundry.load_runtime_config", return_value=config),
1746
+ patch("apherisfold_cli.commands.foundry.open_browser") as browser,
1747
+ ):
1748
+ result = runner.invoke(app, ["jobs", "get", "--id", "foundry_test_001", "--web"])
1749
+ assert isinstance(result.exception, CLIError)
1750
+ assert result.exception.code == 4
1751
+ assert "apheris-foundry login" in result.exception.message
1752
+ assert "secret" not in result.exception.message
1753
+ browser.assert_not_called()
1754
+ assert not any(hub_api_fixture.values())
1755
+
1756
+
1757
+ def test_foundry_get_web_browser_failure_provides_manual_url(hub_api_fixture) -> None:
1758
+ with (
1759
+ patch(
1760
+ "apherisfold_cli.commands.foundry.load_runtime_config",
1761
+ return_value=SimpleNamespace(hub_url="https://hub.example"),
1762
+ ),
1763
+ patch("apherisfold_cli.commands.foundry.open_browser", return_value=False),
1764
+ ):
1765
+ result = runner.invoke(app, ["jobs", "get", "--id", "foundry_test_001", "--web", "--auto"])
1766
+ assert isinstance(result.exception, CLIError)
1767
+ assert result.exception.code == 4
1768
+ assert "Open this URL manually: https://hub.example/jobs/foundry_test_001" in result.exception.message
1769
+ assert not any(hub_api_fixture.values())
1770
+
1771
+
1772
+ @pytest.mark.parametrize("force_terminal", [False, True])
1773
+ def test_foundry_get_help_lists_web_option(monkeypatch, force_terminal) -> None:
1774
+ # Typer reads terminal settings at import time; CI can also enable ANSI styling.
1775
+ monkeypatch.setattr("typer.rich_utils.MAX_WIDTH", 200)
1776
+ monkeypatch.setattr("typer.rich_utils.FORCE_TERMINAL", force_terminal)
1777
+ result = runner.invoke(app, ["jobs", "get", "--help"], env={"TERM": "xterm-256color"})
1778
+
1779
+ assert result.exit_code == 0
1780
+ help_text = Text.from_ansi(result.stdout).plain
1781
+ for text in ["--web", "--auto", "default browser"]:
1782
+ assert text in help_text
1783
+
1784
+
1785
+ def test_foundry_get_auto_requires_web(hub_api_fixture) -> None:
1786
+ with patch("apherisfold_cli.commands.foundry.open_browser") as browser:
1787
+ result = runner.invoke(app, ["jobs", "get", "--id", "foundry_test_001", "--auto"])
1788
+ assert isinstance(result.exception, CLIError)
1789
+ assert result.exception.code == 2
1790
+ assert result.exception.message == "--auto requires --web."
1791
+ browser.assert_not_called()
1792
+ assert not any(hub_api_fixture.values())
1793
+
1794
+
1657
1795
  def test_foundry_get_shows_run_details(hub_api_fixture) -> None:
1658
1796
  result = runner.invoke(app, ["jobs", "get", "--id", "foundry_test_001"], env={"COLUMNS": "200"})
1659
1797
  assert result.exit_code == 0
@@ -100,3 +100,91 @@ def test_document_path_encoding(monkeypatch):
100
100
  monkeypatch.setattr(hub_requests, "_request_json", lambda **kwargs: calls.append(kwargs) or {})
101
101
  hub_requests.get_hub_document("releases/example/a page.md")
102
102
  assert calls[0]["path"] == "/api/v1/docs/pages/releases/example/a%20page.md"
103
+
104
+
105
+ RELEASES_INDEX = {
106
+ "hubVersion": "1.2.0",
107
+ "toolkitVersion": "v0.1.1-0.20261103113419-2c72f429d059",
108
+ "navigation": [
109
+ {"title": "Overview", "path": "index.md"},
110
+ {"title": "Deployment", "children": [{"title": "Upgrade", "path": "deployment/upgrade.md", "draft": True}]},
111
+ {
112
+ "title": "Releases",
113
+ "children": [
114
+ {
115
+ "title": f"Foundry {version}",
116
+ "children": [
117
+ {"title": "Release notes", "path": f"releases/{version}/release-notes.md"},
118
+ {"title": "Known issues", "path": f"releases/{version}/known-issues.md"},
119
+ ],
120
+ }
121
+ for version in ("1.2.0", "1.1.0")
122
+ ],
123
+ },
124
+ ],
125
+ }
126
+
127
+
128
+ @pytest.fixture
129
+ def releases(monkeypatch):
130
+ monkeypatch.setattr(docs, "get_hub_documentation_index", lambda: RELEASES_INDEX)
131
+
132
+
133
+ def _rows(output: str) -> list[str]:
134
+ return [" ".join(line.split()) for line in output.splitlines() if ".md" in line]
135
+
136
+
137
+ def test_list_names_sections_releases_drafts_and_builds(releases):
138
+ result = runner.invoke(app, ["docs", "list"], env={"COLUMNS": "120"})
139
+ assert result.exit_code == 0, result.output
140
+ assert _rows(result.output) == [
141
+ "Overview index.md",
142
+ "Deployment Upgrade Draft deployment/upgrade.md",
143
+ "Releases › Foundry 1.2.0 (latest) Release notes releases/1.2.0/release-notes.md",
144
+ "Releases › Foundry 1.2.0 (latest) Known issues releases/1.2.0/known-issues.md",
145
+ "Releases › Foundry 1.1.0 Release notes releases/1.1.0/release-notes.md",
146
+ "Releases › Foundry 1.1.0 Known issues releases/1.1.0/known-issues.md",
147
+ ]
148
+ assert "Hub 1.2.0 · foundry-toolkit commit 2c72f42" in result.output
149
+
150
+
151
+ def test_list_filters_one_release_and_explains_unknown_ones(releases):
152
+ result = runner.invoke(app, ["docs", "list", "--release", "1.1.0"], env={"COLUMNS": "120"})
153
+ assert result.exit_code == 0, result.output
154
+ assert [row.split()[-1] for row in _rows(result.output)] == [
155
+ "releases/1.1.0/release-notes.md",
156
+ "releases/1.1.0/known-issues.md",
157
+ ]
158
+ assert runner.invoke(app, ["docs", "list", "--release", "Foundry 1.2.0"]).exit_code == 0
159
+ missing = runner.invoke(app, ["docs", "list", "--release", "9.9"])
160
+ assert isinstance(missing.exception, CLIError)
161
+ assert "Foundry 1.2.0, Foundry 1.1.0" in missing.exception.message
162
+
163
+
164
+ def test_list_json_returns_the_original_navigation(releases):
165
+ result = runner.invoke(app, ["docs", "list", "--release", "1.1.0", "--json"])
166
+ assert json.loads(result.output) == RELEASES_INDEX
167
+
168
+
169
+ @pytest.mark.parametrize(
170
+ ("version", "label"), [("v1.1.3", "v1.1.3"), ("v0.0.0-20261103113419-2c72f429d059", "commit 2c72f42")]
171
+ )
172
+ def test_module_version_labels(version, label):
173
+ assert docs._module_version(version) == label
174
+
175
+
176
+ def test_older_hub_without_toolkit_version(monkeypatch):
177
+ index = {"hubVersion": "old", "navigation": [{"title": "Overview", "path": "index.md"}]}
178
+ monkeypatch.setattr(docs, "get_hub_documentation_index", lambda: index)
179
+ result = runner.invoke(app, ["docs", "list"])
180
+ assert result.exit_code == 0, result.output
181
+ assert "Hub old" in result.output and "foundry-toolkit" not in result.output
182
+
183
+
184
+ def test_show_marks_draft_documents(document):
185
+ document["draft"] = True
186
+ result = runner.invoke(app, ["docs", "show", PATH])
187
+ assert result.exit_code == 0, result.output
188
+ assert "Draft: unreviewed" in result.output
189
+ raw = runner.invoke(app, ["docs", "show", PATH, "--raw"])
190
+ assert raw.stdout_bytes == CONTENT.encode()
@@ -1 +0,0 @@
1
- __version__ = "2.3.0"