mcpjungle 1.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,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcpjungle
3
+ Version: 1.0.0
4
+ Summary: Installer for the cmdop CLI — one AI agent that reaches all your machines
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,cli,cmdop,fleet,installer,mcp,self-hosted
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
+ # mcpjungle
32
+
33
+ ![cmdop — messenger for AI agents](https://raw.githubusercontent.com/commandoperator/assets/b72b9ac6c796b958a038f684b323c7be49a49c9d/promo/social.webp)
34
+
35
+ **Installer for the [cmdop](https://cmdop.com) CLI** — stop keeping a directory of endpoints in your head.
36
+
37
+ ```bash
38
+ pip install mcpjungle
39
+ mcpjungle
40
+ ```
41
+
42
+ That's it. `mcpjungle` detects your platform, downloads the `cmdop` binary,
43
+ verifies it against the published checksums, installs it, and hands over.
44
+
45
+ > **Not affiliated with the MCPJungle project.** If you are looking for
46
+ > [github.com/mcpjungle/MCPJungle](https://github.com/mcpjungle/MCPJungle),
47
+ > that is a different project — this package will not install it. This
48
+ > package is published by CMDOP and installs the `cmdop` CLI.
49
+
50
+ Anyone running more than three machines ends up maintaining a private index: which host has the GPU, which one has the database, which SSH alias still works. The index lives in your head and goes stale quietly.
51
+
52
+ `cmdop` replaces it with something you can address by name. One binary per machine, one place to talk to all of them. This package installs that binary.
53
+
54
+ **How does CMDOP compare?**
55
+ [CMDOP Skills vs OpenClaw: two approaches to AI agent skills →](https://docs.cmdop.com/blog/cmdop-skills-vs-openclaw)
56
+
57
+ ## Naming a machine beats remembering its address
58
+
59
+ Machines join a fleet and get a name. What changes is not the connection — it is that you stop needing to recall how to make one before you can ask a question.
60
+
61
+ The agent runs where the work is, with the files and credentials already on that box. Nothing is uploaded anywhere to make it reachable.
62
+
63
+ ## What is cmdop
64
+
65
+ One executable that is the agent, the relay, the local server and the web
66
+ console at once. There is no gateway, backend, database server or broker to
67
+ stand up — you add one binary to a machine you already own.
68
+
69
+ - run an AI agent on your own machine, with your own tools
70
+ - reach it from anywhere: terminal, files, remote execution
71
+ - connect machines into a fleet
72
+ - works with Claude Code and other agent engines under the hood
73
+
74
+ Full documentation: **[docs.cmdop.com](https://docs.cmdop.com)**
75
+
76
+ ## Usage
77
+
78
+ ```bash
79
+ mcpjungle # install cmdop (if needed), then run it
80
+ mcpjungle --install-only # install, don't hand over
81
+ mcpjungle --prefix ~/bin # choose the install directory
82
+ mcpjungle --force # reinstall even if already present
83
+ mcpjungle --quiet # print only the installed path
84
+ mcpjungle -- --help # everything after `--` goes to cmdop
85
+ ```
86
+
87
+ Default install directory is `~/.local/bin` (`%LOCALAPPDATA%\cmdop\bin` on
88
+ Windows). No `sudo`, no system directories.
89
+
90
+ ## What it does, precisely
91
+
92
+ 1. Detects your OS and architecture.
93
+ 2. Fetches `SHA256SUMS` from `install.cmdop.com`.
94
+ 3. Downloads the matching binary to a temporary file.
95
+ 4. **Verifies the SHA-256 against the published checksum.** On mismatch it
96
+ aborts and installs nothing.
97
+ 5. Moves the verified binary into the install directory and marks it
98
+ executable.
99
+ 6. Runs it.
100
+
101
+ Supported: macOS (Apple Silicon, Intel), Linux (x64, arm64), Windows (x64).
102
+
103
+ ## What it does not do
104
+
105
+ - **No side effects at install time.** `pip install mcpjungle` only unpacks
106
+ files. Nothing is downloaded or executed until you run `mcpjungle`.
107
+ - **No network access on import.** `import mcpjungle` touches nothing.
108
+ - **No telemetry.** The package sends no analytics, ever.
109
+ - **No dependencies.** Standard library only, so there is nothing to conflict
110
+ with what you already have installed.
111
+
112
+ ## Python API
113
+
114
+ The installer is importable if you would rather script it:
115
+
116
+ ```python
117
+ import mcpjungle
118
+
119
+ target = mcpjungle.detect()
120
+ print(target.label, target.asset)
121
+
122
+ result = mcpjungle.install()
123
+ print(result.path, result.sha256)
124
+ ```
125
+
126
+ `mcpjungle.install()` raises `mcpjungle.InstallError` with a user-facing message
127
+ on any failure, and `mcpjungle.UnsupportedPlatform` when there is no published
128
+ binary for the current machine.
129
+
130
+ ## Links
131
+
132
+ - Website — <https://cmdop.com>
133
+ - Documentation — <https://docs.cmdop.com>
134
+ - Downloads — <https://cmdop.com/download>
135
+
136
+ ## License
137
+
138
+ MIT
@@ -0,0 +1,108 @@
1
+ # mcpjungle
2
+
3
+ ![cmdop — messenger for AI agents](https://raw.githubusercontent.com/commandoperator/assets/b72b9ac6c796b958a038f684b323c7be49a49c9d/promo/social.webp)
4
+
5
+ **Installer for the [cmdop](https://cmdop.com) CLI** — stop keeping a directory of endpoints in your head.
6
+
7
+ ```bash
8
+ pip install mcpjungle
9
+ mcpjungle
10
+ ```
11
+
12
+ That's it. `mcpjungle` detects your platform, downloads the `cmdop` binary,
13
+ verifies it against the published checksums, installs it, and hands over.
14
+
15
+ > **Not affiliated with the MCPJungle project.** If you are looking for
16
+ > [github.com/mcpjungle/MCPJungle](https://github.com/mcpjungle/MCPJungle),
17
+ > that is a different project — this package will not install it. This
18
+ > package is published by CMDOP and installs the `cmdop` CLI.
19
+
20
+ Anyone running more than three machines ends up maintaining a private index: which host has the GPU, which one has the database, which SSH alias still works. The index lives in your head and goes stale quietly.
21
+
22
+ `cmdop` replaces it with something you can address by name. One binary per machine, one place to talk to all of them. This package installs that binary.
23
+
24
+ **How does CMDOP compare?**
25
+ [CMDOP Skills vs OpenClaw: two approaches to AI agent skills →](https://docs.cmdop.com/blog/cmdop-skills-vs-openclaw)
26
+
27
+ ## Naming a machine beats remembering its address
28
+
29
+ Machines join a fleet and get a name. What changes is not the connection — it is that you stop needing to recall how to make one before you can ask a question.
30
+
31
+ The agent runs where the work is, with the files and credentials already on that box. Nothing is uploaded anywhere to make it reachable.
32
+
33
+ ## What is cmdop
34
+
35
+ One executable that is the agent, the relay, the local server and the web
36
+ console at once. There is no gateway, backend, database server or broker to
37
+ stand up — you add one binary to a machine you already own.
38
+
39
+ - run an AI agent on your own machine, with your own tools
40
+ - reach it from anywhere: terminal, files, remote execution
41
+ - connect machines into a fleet
42
+ - works with Claude Code and other agent engines under the hood
43
+
44
+ Full documentation: **[docs.cmdop.com](https://docs.cmdop.com)**
45
+
46
+ ## Usage
47
+
48
+ ```bash
49
+ mcpjungle # install cmdop (if needed), then run it
50
+ mcpjungle --install-only # install, don't hand over
51
+ mcpjungle --prefix ~/bin # choose the install directory
52
+ mcpjungle --force # reinstall even if already present
53
+ mcpjungle --quiet # print only the installed path
54
+ mcpjungle -- --help # everything after `--` goes to cmdop
55
+ ```
56
+
57
+ Default install directory is `~/.local/bin` (`%LOCALAPPDATA%\cmdop\bin` on
58
+ Windows). No `sudo`, no system directories.
59
+
60
+ ## What it does, precisely
61
+
62
+ 1. Detects your OS and architecture.
63
+ 2. Fetches `SHA256SUMS` from `install.cmdop.com`.
64
+ 3. Downloads the matching binary to a temporary file.
65
+ 4. **Verifies the SHA-256 against the published checksum.** On mismatch it
66
+ aborts and installs nothing.
67
+ 5. Moves the verified binary into the install directory and marks it
68
+ executable.
69
+ 6. Runs it.
70
+
71
+ Supported: macOS (Apple Silicon, Intel), Linux (x64, arm64), Windows (x64).
72
+
73
+ ## What it does not do
74
+
75
+ - **No side effects at install time.** `pip install mcpjungle` only unpacks
76
+ files. Nothing is downloaded or executed until you run `mcpjungle`.
77
+ - **No network access on import.** `import mcpjungle` touches nothing.
78
+ - **No telemetry.** The package sends no analytics, ever.
79
+ - **No dependencies.** Standard library only, so there is nothing to conflict
80
+ with what you already have installed.
81
+
82
+ ## Python API
83
+
84
+ The installer is importable if you would rather script it:
85
+
86
+ ```python
87
+ import mcpjungle
88
+
89
+ target = mcpjungle.detect()
90
+ print(target.label, target.asset)
91
+
92
+ result = mcpjungle.install()
93
+ print(result.path, result.sha256)
94
+ ```
95
+
96
+ `mcpjungle.install()` raises `mcpjungle.InstallError` with a user-facing message
97
+ on any failure, and `mcpjungle.UnsupportedPlatform` when there is no published
98
+ binary for the current machine.
99
+
100
+ ## Links
101
+
102
+ - Website — <https://cmdop.com>
103
+ - Documentation — <https://docs.cmdop.com>
104
+ - Downloads — <https://cmdop.com/download>
105
+
106
+ ## License
107
+
108
+ 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 = "mcpjungle"
14
+ version = "1.0.0"
15
+ description = "Installer for the cmdop CLI — one AI agent that reaches all your machines"
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
+ "mcp",
25
+ "fleet",
26
+ "self-hosted",
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
+ mcpjungle = "mcpjungle.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/mcpjungle"]
76
+
77
+ [tool.hatch.build.targets.sdist]
78
+ include = ["src/mcpjungle", "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,61 @@
1
+ """mcpjungle — installer for the cmdop CLI.
2
+
3
+ Run `mcpjungle` to download, verify and launch cmdop on this machine.
4
+
5
+ Not affiliated with the MCPJungle project (github.com/mcpjungle/MCPJungle).
6
+ This package is published by CMDOP — https://cmdop.com
7
+
8
+ Importing this module performs no network access and has no side effects.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import TYPE_CHECKING
14
+
15
+ if TYPE_CHECKING: # pragma: no cover — for type checkers and IDE completion only
16
+ from .cli import main
17
+ from .installer import (
18
+ InstallError,
19
+ InstallResult,
20
+ default_install_dir,
21
+ find_installed,
22
+ install,
23
+ )
24
+ from .platform import Platform, UnsupportedPlatform, detect
25
+
26
+ __version__ = "1.0.0"
27
+
28
+ __all__ = [
29
+ "__version__",
30
+ "InstallError",
31
+ "InstallResult",
32
+ "Platform",
33
+ "UnsupportedPlatform",
34
+ "default_install_dir",
35
+ "detect",
36
+ "find_installed",
37
+ "install",
38
+ "main",
39
+ ]
40
+
41
+
42
+ def __getattr__(name: str):
43
+ """Resolve the public API lazily.
44
+
45
+ Keeps `import mcpjungle` free of any work beyond binding a name — the
46
+ submodules import argparse, subprocess and urllib, none of which a caller
47
+ who only wants __version__ should pay for.
48
+ """
49
+ if name in ("InstallError", "InstallResult", "default_install_dir", "find_installed", "install"):
50
+ from . import installer
51
+
52
+ return getattr(installer, name)
53
+ if name in ("Platform", "UnsupportedPlatform", "detect"):
54
+ from . import platform as _platform
55
+
56
+ return getattr(_platform, name)
57
+ if name == "main":
58
+ from .cli import main
59
+
60
+ return main
61
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,182 @@
1
+ """The `mcpjungle` command.
2
+
3
+ Bare `mcpjungle` 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="mcpjungle",
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 `mcpjungle` to "
107
+ f"install it and get started. {DOCS_URL}"
108
+ ),
109
+ epilog=(
110
+ "Not affiliated with the MCPJungle project "
111
+ "(github.com/mcpjungle/MCPJungle). This package is published by CMDOP."
112
+ ),
113
+ )
114
+ parser.add_argument("--version", action="store_true", help="show version and exit")
115
+ parser.add_argument("--prefix", metavar="DIR", help="install directory")
116
+ parser.add_argument(
117
+ "--force", action="store_true", help="reinstall even if cmdop is present"
118
+ )
119
+ parser.add_argument(
120
+ "--quiet", action="store_true", help="print only the installed path"
121
+ )
122
+ parser.add_argument(
123
+ "--install-only",
124
+ action="store_true",
125
+ help="install without handing over to cmdop",
126
+ )
127
+
128
+ # Everything after `--` goes to cmdop untouched.
129
+ passthrough: list[str] = []
130
+ if "--" in argv:
131
+ split = argv.index("--")
132
+ argv, passthrough = argv[:split], argv[split + 1 :]
133
+
134
+ args = parser.parse_args(argv)
135
+
136
+ if args.version:
137
+ print(f"mcpjungle {__version__}")
138
+ return 0
139
+
140
+ install_dir = Path(args.prefix).expanduser() if args.prefix else None
141
+ binary_name = "cmdop.exe" if is_windows() else "cmdop"
142
+
143
+ # An explicit --prefix names exactly where the binary belongs, so only that
144
+ # location counts as "already installed". Without it, any cmdop on PATH
145
+ # does. Checking PATH under --prefix would silently skip the install the
146
+ # user just asked for.
147
+ if install_dir is not None:
148
+ candidate = install_dir / binary_name
149
+ existing = candidate if candidate.exists() else None
150
+ else:
151
+ existing = find_installed()
152
+
153
+ if args.force:
154
+ existing = None
155
+
156
+ if existing is None:
157
+ code = _install(install_dir, args.quiet)
158
+ if code != 0:
159
+ return code
160
+ existing = (install_dir or default_install_dir()) / binary_name
161
+ if not existing.exists():
162
+ found = find_installed()
163
+ if found is None:
164
+ print("error: install reported success but no binary was found.",
165
+ file=sys.stderr)
166
+ return 1
167
+ existing = found
168
+ if not args.quiet and not args.install_only:
169
+ print()
170
+ elif not args.quiet:
171
+ # Say so even under --install-only: a command that does nothing must
172
+ # still tell the user why.
173
+ print(_dim(f"cmdop is already installed at {existing}"))
174
+
175
+ if args.install_only:
176
+ return 0
177
+
178
+ return _run(existing, passthrough)
179
+
180
+
181
+ if __name__ == "__main__": # pragma: no cover
182
+ 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 = "mcpjungle-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="mcpjungle-") 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")