scoutagent 2.0.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.
@@ -0,0 +1,32 @@
1
+ # Secrets — never commit, even to a private repo.
2
+ # Git history is permanent, and private repos get shared or opened later.
3
+ .env
4
+ .env.*
5
+ !.env.example
6
+ *.pem
7
+ *.key
8
+
9
+ # Python build output
10
+ #
11
+ # NOTE: .archive/ contains __pycache__ files that were committed before this
12
+ # rule existed. They stay tracked despite the pattern below (gitignore does not
13
+ # apply to already-tracked files), so a blanket
14
+ # `find . -name __pycache__ -exec rm -rf {} +` will delete real history.
15
+ # Scope such cleanups to the directory you are working in.
16
+ dist/
17
+ build/
18
+ *.egg-info/
19
+ __pycache__/
20
+ *.py[cod]
21
+ .pytest_cache/
22
+ .venv/
23
+ venv/
24
+
25
+ # Node
26
+ node_modules/
27
+
28
+ # Generated imagery is committed deliberately (see @docs/assets.md), but the
29
+ # raw model output used for review is not.
30
+ *.raw.png
31
+
32
+ .DS_Store
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: scoutagent
3
+ Version: 2.0.0
4
+ Summary: Installer for the cmdop CLI — stand up an AI agent on a machine you already have
5
+ Project-URL: Homepage, https://cmdop.com
6
+ Project-URL: Documentation, https://docs.cmdop.com
7
+ Project-URL: Download, https://cmdop.com/download
8
+ Project-URL: Source (organization), https://github.com/commandoperator
9
+ License: MIT
10
+ Keywords: ai-agent,builder,cli,cmdop,deploy,installer,no-code
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Software Development :: Build Tools
26
+ Classifier: Topic :: System :: Installation/Setup
27
+ Classifier: Topic :: System :: Systems Administration
28
+ Requires-Python: >=3.9
29
+ Description-Content-Type: text/markdown
30
+
31
+ # scoutagent
32
+
33
+
34
+ **Installer for the [cmdop](https://cmdop.com) CLI** — one binary that runs an
35
+ AI agent on your machine and connects it to your fleet.
36
+
37
+ ```bash
38
+ pip install scoutagent
39
+ scoutagent
40
+ ```
41
+
42
+ That's it. `scoutagent` detects your platform, downloads the `cmdop` binary,
43
+ verifies it against the published checksums, installs it, and hands over.
44
+
45
+ **How does CMDOP compare?**
46
+ [CMDOP Skills vs OpenClaw: two approaches to AI agent skills →](https://docs.cmdop.com/blog/cmdop-skills-vs-openclaw)
47
+
48
+ ## What is cmdop
49
+
50
+ One executable that is the agent, the relay, the local server and the web
51
+ console at once. There is no gateway, backend, database server or broker to
52
+ stand up — you add one binary to a machine you already own.
53
+
54
+ - run an AI agent on your own machine, with your own tools
55
+ - reach it from anywhere: terminal, files, remote execution
56
+ - connect machines into a fleet
57
+ - works with Claude Code and other agent engines under the hood
58
+
59
+ Full documentation: **[docs.cmdop.com](https://docs.cmdop.com)**
60
+
61
+ ## Usage
62
+
63
+ ```bash
64
+ scoutagent # install cmdop (if needed), then run it
65
+ scoutagent --install-only # install, don't hand over
66
+ scoutagent --prefix ~/bin # choose the install directory
67
+ scoutagent --force # reinstall even if already present
68
+ scoutagent --quiet # print only the installed path
69
+ scoutagent -- --help # everything after `--` goes to cmdop
70
+ ```
71
+
72
+ Default install directory is `~/.local/bin` (`%LOCALAPPDATA%\cmdop\bin` on
73
+ Windows). No `sudo`, no system directories.
74
+
75
+ ## What it does, precisely
76
+
77
+ 1. Detects your OS and architecture.
78
+ 2. Fetches `SHA256SUMS` from `install.cmdop.com`.
79
+ 3. Downloads the matching binary to a temporary file.
80
+ 4. **Verifies the SHA-256 against the published checksum.** On mismatch it
81
+ aborts and installs nothing.
82
+ 5. Moves the verified binary into the install directory and marks it
83
+ executable.
84
+ 6. Runs it.
85
+
86
+ Supported: macOS (Apple Silicon, Intel), Linux (x64, arm64), Windows (x64).
87
+
88
+ ## What it does not do
89
+
90
+ - **No side effects at install time.** `pip install scoutagent` only unpacks
91
+ files. Nothing is downloaded or executed until you run `scoutagent`.
92
+ - **No network access on import.** `import scoutagent` touches nothing.
93
+ - **No telemetry.** The package sends no analytics, ever.
94
+ - **No dependencies.** Standard library only, so there is nothing to conflict
95
+ with what you already have installed.
96
+
97
+ ## Python API
98
+
99
+ The installer is importable if you would rather script it:
100
+
101
+ ```python
102
+ import scoutagent
103
+
104
+ target = scoutagent.detect()
105
+ print(target.label, target.asset)
106
+
107
+ result = scoutagent.install()
108
+ print(result.path, result.sha256)
109
+ ```
110
+
111
+ `scoutagent.install()` raises `scoutagent.InstallError` with a user-facing message
112
+ on any failure, and `scoutagent.UnsupportedPlatform` when there is no published
113
+ binary for the current machine.
114
+
115
+ ## Links
116
+
117
+ - Website — <https://cmdop.com>
118
+ - Documentation — <https://docs.cmdop.com>
119
+ - Downloads — <https://cmdop.com/download>
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,93 @@
1
+ # scoutagent
2
+
3
+
4
+ **Installer for the [cmdop](https://cmdop.com) CLI** — one binary that runs an
5
+ AI agent on your machine and connects it to your fleet.
6
+
7
+ ```bash
8
+ pip install scoutagent
9
+ scoutagent
10
+ ```
11
+
12
+ That's it. `scoutagent` detects your platform, downloads the `cmdop` binary,
13
+ verifies it against the published checksums, installs it, and hands over.
14
+
15
+ **How does CMDOP compare?**
16
+ [CMDOP Skills vs OpenClaw: two approaches to AI agent skills →](https://docs.cmdop.com/blog/cmdop-skills-vs-openclaw)
17
+
18
+ ## What is cmdop
19
+
20
+ One executable that is the agent, the relay, the local server and the web
21
+ console at once. There is no gateway, backend, database server or broker to
22
+ stand up — you add one binary to a machine you already own.
23
+
24
+ - run an AI agent on your own machine, with your own tools
25
+ - reach it from anywhere: terminal, files, remote execution
26
+ - connect machines into a fleet
27
+ - works with Claude Code and other agent engines under the hood
28
+
29
+ Full documentation: **[docs.cmdop.com](https://docs.cmdop.com)**
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ scoutagent # install cmdop (if needed), then run it
35
+ scoutagent --install-only # install, don't hand over
36
+ scoutagent --prefix ~/bin # choose the install directory
37
+ scoutagent --force # reinstall even if already present
38
+ scoutagent --quiet # print only the installed path
39
+ scoutagent -- --help # everything after `--` goes to cmdop
40
+ ```
41
+
42
+ Default install directory is `~/.local/bin` (`%LOCALAPPDATA%\cmdop\bin` on
43
+ Windows). No `sudo`, no system directories.
44
+
45
+ ## What it does, precisely
46
+
47
+ 1. Detects your OS and architecture.
48
+ 2. Fetches `SHA256SUMS` from `install.cmdop.com`.
49
+ 3. Downloads the matching binary to a temporary file.
50
+ 4. **Verifies the SHA-256 against the published checksum.** On mismatch it
51
+ aborts and installs nothing.
52
+ 5. Moves the verified binary into the install directory and marks it
53
+ executable.
54
+ 6. Runs it.
55
+
56
+ Supported: macOS (Apple Silicon, Intel), Linux (x64, arm64), Windows (x64).
57
+
58
+ ## What it does not do
59
+
60
+ - **No side effects at install time.** `pip install scoutagent` only unpacks
61
+ files. Nothing is downloaded or executed until you run `scoutagent`.
62
+ - **No network access on import.** `import scoutagent` touches nothing.
63
+ - **No telemetry.** The package sends no analytics, ever.
64
+ - **No dependencies.** Standard library only, so there is nothing to conflict
65
+ with what you already have installed.
66
+
67
+ ## Python API
68
+
69
+ The installer is importable if you would rather script it:
70
+
71
+ ```python
72
+ import scoutagent
73
+
74
+ target = scoutagent.detect()
75
+ print(target.label, target.asset)
76
+
77
+ result = scoutagent.install()
78
+ print(result.path, result.sha256)
79
+ ```
80
+
81
+ `scoutagent.install()` raises `scoutagent.InstallError` with a user-facing message
82
+ on any failure, and `scoutagent.UnsupportedPlatform` when there is no published
83
+ binary for the current machine.
84
+
85
+ ## Links
86
+
87
+ - Website — <https://cmdop.com>
88
+ - Documentation — <https://docs.cmdop.com>
89
+ - Downloads — <https://cmdop.com/download>
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,83 @@
1
+ [build-system]
2
+ # Pinned, and for the same reason this whole fleet needed repairing: a bare
3
+ # `hatchling` floats. On 2026-08-13 it began emitting Metadata-Version 2.5,
4
+ # which `packaging` (and therefore twine's check) does not accept — every
5
+ # build failed validation with "'2.5' is not a valid metadata version".
6
+ #
7
+ # The build backend is a dependency like any other. Raise this deliberately,
8
+ # after checking twine can still read what it produces.
9
+ requires = ["hatchling>=1.21,<1.28"]
10
+ build-backend = "hatchling.build"
11
+
12
+ [project]
13
+ name = "scoutagent"
14
+ version = "2.0.0"
15
+ description = "Installer for the cmdop CLI — stand up an AI agent on a machine you already have"
16
+ readme = "README.md"
17
+ license = { text = "MIT" }
18
+ requires-python = ">=3.9"
19
+ keywords = [
20
+ "cmdop",
21
+ "installer",
22
+ "cli",
23
+ "ai-agent",
24
+ "builder",
25
+ "deploy",
26
+ "no-code",
27
+ ]
28
+ classifiers = [
29
+ "Development Status :: 4 - Beta",
30
+ "Environment :: Console",
31
+ "Intended Audience :: Developers",
32
+ "Intended Audience :: System Administrators",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Operating System :: MacOS :: MacOS X",
35
+ "Operating System :: Microsoft :: Windows",
36
+ "Operating System :: POSIX :: Linux",
37
+ "Programming Language :: Python :: 3",
38
+ "Programming Language :: Python :: 3.9",
39
+ "Programming Language :: Python :: 3.10",
40
+ "Programming Language :: Python :: 3.11",
41
+ "Programming Language :: Python :: 3.12",
42
+ "Programming Language :: Python :: 3.13",
43
+ "Topic :: Software Development :: Build Tools",
44
+ "Topic :: System :: Installation/Setup",
45
+ "Topic :: System :: Systems Administration",
46
+ ]
47
+
48
+ # No runtime dependencies, deliberately.
49
+ #
50
+ # An installer must work on any machine that can run Python, and every
51
+ # dependency is a way for that to stop being true. The whole package is
52
+ # stdlib-only: urllib for the download, hashlib for verification.
53
+ #
54
+ # This is also the direct fix for what broke the previous fleet: a bare,
55
+ # unpinned `cmdop` dependency floated onto an SDK release that renamed its
56
+ # client class, and all 12 packages began failing at import. No dependency,
57
+ # no such failure mode.
58
+ dependencies = []
59
+
60
+ [project.scripts]
61
+ scoutagent = "scoutagent.cli:main"
62
+
63
+ [project.urls]
64
+ # `Repository` is deliberately omitted until a real public repo exists for this
65
+ # package under github.com/commandoperator. A Repository link that 404s is
66
+ # worse than none — it is the first thing a cautious developer clicks, and the
67
+ # previous fleet pointed at cmdop-sdk, which was never where its source lived.
68
+ # Add it here the moment the repo is published.
69
+ Homepage = "https://cmdop.com"
70
+ Documentation = "https://docs.cmdop.com"
71
+ Download = "https://cmdop.com/download"
72
+ "Source (organization)" = "https://github.com/commandoperator"
73
+
74
+ [tool.hatch.build.targets.wheel]
75
+ packages = ["src/scoutagent"]
76
+
77
+ [tool.hatch.build.targets.sdist]
78
+ include = ["src/scoutagent", "README.md", "tests"]
79
+
80
+ [tool.pytest.ini_options]
81
+ testpaths = ["tests"]
82
+ markers = ["live: touches the real published manifest (opt-in: pytest -m live)"]
83
+ addopts = "-m 'not live'"
@@ -0,0 +1,60 @@
1
+ """scoutagent — installer for the cmdop CLI.
2
+
3
+ Run `scoutagent` to download, verify and launch cmdop on this machine.
4
+
5
+ This package is published by CMDOP — https://cmdop.com
6
+
7
+ Importing this module performs no network access and has no side effects.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING
13
+
14
+ if TYPE_CHECKING: # pragma: no cover — for type checkers and IDE completion only
15
+ from .cli import main
16
+ from .installer import (
17
+ InstallError,
18
+ InstallResult,
19
+ default_install_dir,
20
+ find_installed,
21
+ install,
22
+ )
23
+ from .platform import Platform, UnsupportedPlatform, detect
24
+
25
+ __version__ = "2.0.0"
26
+
27
+ __all__ = [
28
+ "__version__",
29
+ "InstallError",
30
+ "InstallResult",
31
+ "Platform",
32
+ "UnsupportedPlatform",
33
+ "default_install_dir",
34
+ "detect",
35
+ "find_installed",
36
+ "install",
37
+ "main",
38
+ ]
39
+
40
+
41
+ def __getattr__(name: str):
42
+ """Resolve the public API lazily.
43
+
44
+ Keeps `import scoutagent` free of any work beyond binding a name — the
45
+ submodules import argparse, subprocess and urllib, none of which a caller
46
+ who only wants __version__ should pay for.
47
+ """
48
+ if name in ("InstallError", "InstallResult", "default_install_dir", "find_installed", "install"):
49
+ from . import installer
50
+
51
+ return getattr(installer, name)
52
+ if name in ("Platform", "UnsupportedPlatform", "detect"):
53
+ from . import platform as _platform
54
+
55
+ return getattr(_platform, name)
56
+ if name == "main":
57
+ from .cli import main
58
+
59
+ return main
60
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,179 @@
1
+ """The `scoutagent` command.
2
+
3
+ Bare `scoutagent` does the obvious thing: install cmdop if missing, then hand
4
+ over to it. No subcommand to learn, no flags required.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import os
11
+ import subprocess
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ from . import __version__
16
+ from .installer import (
17
+ InstallError,
18
+ default_install_dir,
19
+ find_installed,
20
+ install,
21
+ )
22
+ from .platform import UnsupportedPlatform, detect, is_windows
23
+
24
+ DOCS_URL = "https://cmdop.com"
25
+
26
+
27
+ def _tty() -> bool:
28
+ return sys.stdout.isatty()
29
+
30
+
31
+ def _dim(text: str) -> str:
32
+ return f"\033[2m{text}\033[0m" if _tty() else text
33
+
34
+
35
+ def _bold(text: str) -> str:
36
+ return f"\033[1m{text}\033[0m" if _tty() else text
37
+
38
+
39
+ def _progress(seen: int, total: int) -> None:
40
+ if not _tty():
41
+ return
42
+ if total:
43
+ pct = seen * 100 // total
44
+ bar = "█" * (pct // 4) + "░" * (25 - pct // 4)
45
+ sys.stdout.write(f"\r {bar} {pct:3d}% {seen / 1048576:.0f}/{total / 1048576:.0f} MB")
46
+ else:
47
+ sys.stdout.write(f"\r {seen / 1048576:.0f} MB")
48
+ sys.stdout.flush()
49
+
50
+
51
+ def _install(install_dir: Path | None, quiet: bool) -> int:
52
+ try:
53
+ target = detect()
54
+ except UnsupportedPlatform as exc:
55
+ print(f"error: {exc}", file=sys.stderr)
56
+ return 2
57
+
58
+ if not quiet:
59
+ print(f"Installing {_bold('cmdop')} for {target.label}…")
60
+
61
+ try:
62
+ result = install(install_dir=install_dir, target=target, on_progress=_progress)
63
+ except InstallError as exc:
64
+ if _tty():
65
+ sys.stdout.write("\r\033[K")
66
+ print(f"error: {exc}", file=sys.stderr)
67
+ return 1
68
+
69
+ if _tty():
70
+ sys.stdout.write("\r\033[K")
71
+
72
+ if quiet:
73
+ print(result.path)
74
+ return 0
75
+
76
+ print(f" Installed {_bold(str(result.path))}")
77
+ print(_dim(f" sha256 {result.sha256}"))
78
+
79
+ if not result.on_path:
80
+ print()
81
+ print(f" {result.path.parent} is not on your PATH. Add it:")
82
+ if is_windows():
83
+ print(_dim(f' setx PATH "%PATH%;{result.path.parent}"'))
84
+ else:
85
+ shell = Path(os.environ.get("SHELL", "")).name or "bash"
86
+ rc = "~/.zshrc" if shell == "zsh" else "~/.bashrc"
87
+ print(_dim(f' echo \'export PATH="{result.path.parent}:$PATH"\' >> {rc}'))
88
+ return 0
89
+
90
+
91
+ def _run(binary: Path, argv: list[str]) -> int:
92
+ try:
93
+ return subprocess.call([str(binary), *argv])
94
+ except OSError as exc:
95
+ print(f"error: could not run {binary}: {exc}", file=sys.stderr)
96
+ return 1
97
+
98
+
99
+ def main(argv: list[str] | None = None) -> int:
100
+ argv = list(sys.argv[1:] if argv is None else argv)
101
+
102
+ parser = argparse.ArgumentParser(
103
+ prog="scoutagent",
104
+ description=(
105
+ "Installer for the cmdop CLI — one binary that runs an AI agent on "
106
+ "your machine and connects it to your fleet. Run `scoutagent` to "
107
+ f"install it and get started. {DOCS_URL}"
108
+ ),
109
+ epilog="Published by CMDOP.",
110
+ )
111
+ parser.add_argument("--version", action="store_true", help="show version and exit")
112
+ parser.add_argument("--prefix", metavar="DIR", help="install directory")
113
+ parser.add_argument(
114
+ "--force", action="store_true", help="reinstall even if cmdop is present"
115
+ )
116
+ parser.add_argument(
117
+ "--quiet", action="store_true", help="print only the installed path"
118
+ )
119
+ parser.add_argument(
120
+ "--install-only",
121
+ action="store_true",
122
+ help="install without handing over to cmdop",
123
+ )
124
+
125
+ # Everything after `--` goes to cmdop untouched.
126
+ passthrough: list[str] = []
127
+ if "--" in argv:
128
+ split = argv.index("--")
129
+ argv, passthrough = argv[:split], argv[split + 1 :]
130
+
131
+ args = parser.parse_args(argv)
132
+
133
+ if args.version:
134
+ print(f"scoutagent {__version__}")
135
+ return 0
136
+
137
+ install_dir = Path(args.prefix).expanduser() if args.prefix else None
138
+ binary_name = "cmdop.exe" if is_windows() else "cmdop"
139
+
140
+ # An explicit --prefix names exactly where the binary belongs, so only that
141
+ # location counts as "already installed". Without it, any cmdop on PATH
142
+ # does. Checking PATH under --prefix would silently skip the install the
143
+ # user just asked for.
144
+ if install_dir is not None:
145
+ candidate = install_dir / binary_name
146
+ existing = candidate if candidate.exists() else None
147
+ else:
148
+ existing = find_installed()
149
+
150
+ if args.force:
151
+ existing = None
152
+
153
+ if existing is None:
154
+ code = _install(install_dir, args.quiet)
155
+ if code != 0:
156
+ return code
157
+ existing = (install_dir or default_install_dir()) / binary_name
158
+ if not existing.exists():
159
+ found = find_installed()
160
+ if found is None:
161
+ print("error: install reported success but no binary was found.",
162
+ file=sys.stderr)
163
+ return 1
164
+ existing = found
165
+ if not args.quiet and not args.install_only:
166
+ print()
167
+ elif not args.quiet:
168
+ # Say so even under --install-only: a command that does nothing must
169
+ # still tell the user why.
170
+ print(_dim(f"cmdop is already installed at {existing}"))
171
+
172
+ if args.install_only:
173
+ return 0
174
+
175
+ return _run(existing, passthrough)
176
+
177
+
178
+ if __name__ == "__main__": # pragma: no cover
179
+ raise SystemExit(main())
@@ -0,0 +1,190 @@
1
+ """Download, verify and install the cmdop binary.
2
+
3
+ Every download is checked against the published SHA256SUMS before anything is
4
+ written to the install directory. A checksum mismatch aborts — an installer
5
+ that would run unverified bytes is worse than no installer.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import os
12
+ import shutil
13
+ import stat
14
+ import tempfile
15
+ import urllib.error
16
+ import urllib.request
17
+ from dataclasses import dataclass
18
+ from pathlib import Path
19
+
20
+ from .platform import Platform, detect, is_windows
21
+
22
+ BASE_URL = "https://install.cmdop.com/cli/latest"
23
+ CHECKSUMS_URL = f"{BASE_URL}/SHA256SUMS"
24
+
25
+ _CHUNK = 64 * 1024
26
+ _TIMEOUT = 60
27
+
28
+ # The distribution edge rejects urllib's default `Python-urllib/3.x` agent with
29
+ # HTTP 403, so every request must carry an explicit one. Identifying the
30
+ # package and version also makes this traffic legible in edge logs.
31
+ _USER_AGENT = "scoutagent-installer/{version} (+https://cmdop.com)"
32
+
33
+
34
+ def _request(url: str) -> urllib.request.Request:
35
+ from . import __version__
36
+
37
+ return urllib.request.Request(
38
+ url, headers={"User-Agent": _USER_AGENT.format(version=__version__)}
39
+ )
40
+
41
+
42
+ class InstallError(RuntimeError):
43
+ """Installation could not be completed. The message is user-facing."""
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class InstallResult:
48
+ path: Path
49
+ sha256: str
50
+ on_path: bool
51
+
52
+
53
+ def default_install_dir() -> Path:
54
+ """Where the binary goes when the user does not choose.
55
+
56
+ A per-user directory, never a system one: it needs no sudo, and an
57
+ installer that silently asks for root is a bad neighbour.
58
+ """
59
+ if is_windows():
60
+ base = os.environ.get("LOCALAPPDATA") or str(Path.home() / "AppData" / "Local")
61
+ return Path(base) / "cmdop" / "bin"
62
+ return Path.home() / ".local" / "bin"
63
+
64
+
65
+ def _fetch(url: str) -> bytes:
66
+ try:
67
+ with urllib.request.urlopen(_request(url), timeout=_TIMEOUT) as response:
68
+ return response.read()
69
+ except urllib.error.HTTPError as exc:
70
+ raise InstallError(f"{url} returned HTTP {exc.code}.") from exc
71
+ except urllib.error.URLError as exc:
72
+ raise InstallError(
73
+ f"Could not reach {url} ({exc.reason}). Check your network and retry."
74
+ ) from exc
75
+
76
+
77
+ def fetch_checksums() -> dict[str, str]:
78
+ """Parse the published SHA256SUMS into {asset: digest}."""
79
+ text = _fetch(CHECKSUMS_URL).decode("utf-8", "replace")
80
+ sums: dict[str, str] = {}
81
+ for line in text.splitlines():
82
+ parts = line.split()
83
+ if len(parts) == 2:
84
+ digest, name = parts
85
+ sums[name.lstrip("*")] = digest.lower()
86
+ if not sums:
87
+ raise InstallError("Published checksum list was empty or malformed.")
88
+ return sums
89
+
90
+
91
+ def _download_verified(url: str, expected: str, dest: Path, on_progress=None) -> str:
92
+ """Stream url to dest, hashing as we go. Returns the digest."""
93
+ digest = hashlib.sha256()
94
+ try:
95
+ with urllib.request.urlopen(_request(url), timeout=_TIMEOUT) as response:
96
+ total = int(response.headers.get("Content-Length") or 0)
97
+ seen = 0
98
+ with open(dest, "wb") as handle:
99
+ while True:
100
+ chunk = response.read(_CHUNK)
101
+ if not chunk:
102
+ break
103
+ handle.write(chunk)
104
+ digest.update(chunk)
105
+ seen += len(chunk)
106
+ if on_progress:
107
+ on_progress(seen, total)
108
+ except urllib.error.HTTPError as exc:
109
+ raise InstallError(f"Download failed: HTTP {exc.code} for {url}.") from exc
110
+ except urllib.error.URLError as exc:
111
+ raise InstallError(f"Download failed: {exc.reason}.") from exc
112
+
113
+ actual = digest.hexdigest()
114
+ if actual != expected:
115
+ dest.unlink(missing_ok=True)
116
+ raise InstallError(
117
+ "Checksum mismatch — the download does not match the published "
118
+ f"SHA256SUMS.\n expected {expected}\n got {actual}\n"
119
+ "Nothing was installed. Retry; if it persists, report it."
120
+ )
121
+ return actual
122
+
123
+
124
+ def install(
125
+ install_dir: Path | None = None,
126
+ target: Platform | None = None,
127
+ on_progress=None,
128
+ ) -> InstallResult:
129
+ """Download the cmdop binary for this machine and install it.
130
+
131
+ Downloads to a temporary file, verifies the checksum, and only then moves
132
+ it into place — an interrupted run never leaves a partial binary where a
133
+ working one is expected.
134
+ """
135
+ target = target or detect()
136
+ install_dir = Path(install_dir) if install_dir else default_install_dir()
137
+
138
+ checksums = fetch_checksums()
139
+ expected = checksums.get(target.asset)
140
+ if not expected:
141
+ raise InstallError(
142
+ f"No published checksum for {target.asset!r}. "
143
+ "This platform may not have a current release."
144
+ )
145
+
146
+ try:
147
+ install_dir.mkdir(parents=True, exist_ok=True)
148
+ except OSError as exc:
149
+ raise InstallError(f"Cannot create {install_dir}: {exc}") from exc
150
+
151
+ final = install_dir / target.binary_name
152
+
153
+ with tempfile.TemporaryDirectory(prefix="scoutagent-") as tmp:
154
+ staged = Path(tmp) / target.binary_name
155
+ digest = _download_verified(
156
+ f"{BASE_URL}/{target.asset}", expected, staged, on_progress
157
+ )
158
+
159
+ if not target.is_windows:
160
+ staged.chmod(staged.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
161
+
162
+ try:
163
+ shutil.move(str(staged), str(final))
164
+ except OSError as exc:
165
+ raise InstallError(f"Cannot write {final}: {exc}") from exc
166
+
167
+ return InstallResult(path=final, sha256=digest, on_path=_on_path(install_dir))
168
+
169
+
170
+ def _on_path(directory: Path) -> bool:
171
+ entries = (os.environ.get("PATH") or "").split(os.pathsep)
172
+ resolved = directory.resolve()
173
+ for entry in entries:
174
+ if not entry:
175
+ continue
176
+ try:
177
+ if Path(entry).resolve() == resolved:
178
+ return True
179
+ except OSError:
180
+ continue
181
+ return False
182
+
183
+
184
+ def find_installed() -> Path | None:
185
+ """Return an existing cmdop on PATH or in the default directory, if any."""
186
+ found = shutil.which("cmdop")
187
+ if found:
188
+ return Path(found)
189
+ candidate = default_install_dir() / ("cmdop.exe" if is_windows() else "cmdop")
190
+ return candidate if candidate.exists() else None
@@ -0,0 +1,87 @@
1
+ """Platform detection.
2
+
3
+ Mirrors the asset naming used by install.cmdop.com. The labels here MUST match
4
+ the names in the published SHA256SUMS file; a mismatch means a 404 at download
5
+ time, so they are asserted against the live manifest in the test suite.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import platform
11
+ import sys
12
+ from dataclasses import dataclass
13
+
14
+ # Asset labels as published in SHA256SUMS.
15
+ _MACOS_SILICON = "macos-silicon"
16
+ _MACOS_INTEL = "macos-intel"
17
+ _LINUX_X64 = "linux-x64"
18
+ _LINUX_ARM64 = "linux-arm64"
19
+ _WINDOWS_X64 = "windows-x64"
20
+
21
+
22
+ class UnsupportedPlatform(RuntimeError):
23
+ """This OS/architecture combination has no published cmdop binary."""
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class Platform:
28
+ """A resolved target: which artifact to fetch and what to call it on disk."""
29
+
30
+ label: str
31
+ binary_name: str
32
+
33
+ @property
34
+ def asset(self) -> str:
35
+ """Filename of the artifact as published in SHA256SUMS."""
36
+ return f"cmdop-{self.label}.exe" if self.is_windows else f"cmdop-{self.label}"
37
+
38
+ @property
39
+ def is_windows(self) -> bool:
40
+ return self.label == _WINDOWS_X64
41
+
42
+
43
+ def detect() -> Platform:
44
+ """Resolve the current machine to a published artifact.
45
+
46
+ Raises UnsupportedPlatform with an actionable message when there is none —
47
+ never guesses an adjacent architecture, because a silently wrong binary is
48
+ a worse failure than a clear refusal.
49
+ """
50
+ system = platform.system().lower()
51
+ machine = platform.machine().lower()
52
+
53
+ if machine in ("x86_64", "amd64"):
54
+ arch = "x64"
55
+ elif machine in ("arm64", "aarch64"):
56
+ arch = "arm64"
57
+ else:
58
+ raise UnsupportedPlatform(
59
+ f"Unsupported architecture: {platform.machine()!r}. "
60
+ "cmdop ships x64 and arm64 builds."
61
+ )
62
+
63
+ if system == "darwin":
64
+ label = _MACOS_SILICON if arch == "arm64" else _MACOS_INTEL
65
+ elif system == "linux":
66
+ label = _LINUX_X64 if arch == "x64" else _LINUX_ARM64
67
+ elif system == "windows":
68
+ if arch != "x64":
69
+ raise UnsupportedPlatform(
70
+ f"Unsupported Windows architecture: {platform.machine()!r}. "
71
+ "cmdop ships an x64 build for Windows."
72
+ )
73
+ label = _WINDOWS_X64
74
+ else:
75
+ raise UnsupportedPlatform(
76
+ f"Unsupported operating system: {platform.system()!r}. "
77
+ "cmdop ships macOS, Linux and Windows builds."
78
+ )
79
+
80
+ return Platform(
81
+ label=label,
82
+ binary_name="cmdop.exe" if label == _WINDOWS_X64 else "cmdop",
83
+ )
84
+
85
+
86
+ def is_windows() -> bool:
87
+ return sys.platform.startswith("win")