cmdop 3.0.1__tar.gz → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cmdop
3
- Version: 3.0.1
3
+ Version: 3.1.0
4
4
  Summary: Your machines' tools from a program: the same tools agents use through MCP, typed from Rust.
5
5
  Project-URL: Homepage, https://cmdop.ai
6
6
  Project-URL: Documentation, https://docs.cmdop.ai/reference/sdk/python
@@ -34,7 +34,8 @@ with cmdop.connect() as c: # CMDOP_TOKEN, CMDOP_URL
34
34
  print(run.result.exit_code)
35
35
  ```
36
36
 
37
- `cmdop.connect_async()` is the same, awaited. `src/cmdop/generated/` is generated by `make sdk-generate`; never edit it.
37
+ Every tool is a typed method on a machine (`box.fs_read(path=...)`), also under its group (`box.fs.read(path=...)`);
38
+ `box.screenshot()` decodes the picture. `cmdop.connect_async()` is the same, awaited. `src/cmdop/generated/` is generated by `make sdk-generate`; never edit it.
38
39
 
39
40
  ## The same tools over MCP
40
41
 
@@ -14,7 +14,8 @@ with cmdop.connect() as c: # CMDOP_TOKEN, CMDOP_URL
14
14
  print(run.result.exit_code)
15
15
  ```
16
16
 
17
- `cmdop.connect_async()` is the same, awaited. `src/cmdop/generated/` is generated by `make sdk-generate`; never edit it.
17
+ Every tool is a typed method on a machine (`box.fs_read(path=...)`), also under its group (`box.fs.read(path=...)`);
18
+ `box.screenshot()` decodes the picture. `cmdop.connect_async()` is the same, awaited. `src/cmdop/generated/` is generated by `make sdk-generate`; never edit it.
18
19
 
19
20
  ## The same tools over MCP
20
21
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cmdop"
3
- version = "3.0.1"
3
+ version = "3.1.0"
4
4
  description = "Your machines' tools from a program: the same tools agents use through MCP, typed from Rust."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -11,13 +11,15 @@ with cmdop.connect() as c: # CMDOP_TOKEN, CMDOP_URL
11
11
  from ._async import AsyncClient, AsyncMachine, AsyncRun, connect_async
12
12
  from ._client import Client, Machine, Piece, Run, connect
13
13
  from ._errors import CarrierError, CmdopError
14
+ from ._screen import DecodedImage, Screenshot
14
15
  from .carriers import AsyncMemoryCarrier, MemoryCarrier
15
16
  from .generated.call import ENVELOPE_MAX_BYTES, ERROR_CODES, PIECE_MAX_BYTES
16
- from .generated.tools import TOOLS
17
+ from .generated.tools import GROUPS, TOOLS
17
18
 
18
19
  __all__ = [
19
20
  "ENVELOPE_MAX_BYTES",
20
21
  "ERROR_CODES",
22
+ "GROUPS",
21
23
  "PIECE_MAX_BYTES",
22
24
  "TOOLS",
23
25
  "AsyncClient",
@@ -27,10 +29,12 @@ __all__ = [
27
29
  "CarrierError",
28
30
  "Client",
29
31
  "CmdopError",
32
+ "DecodedImage",
30
33
  "Machine",
31
34
  "MemoryCarrier",
32
35
  "Piece",
33
36
  "Run",
37
+ "Screenshot",
34
38
  "connect",
35
39
  "connect_async",
36
40
  ]
@@ -7,15 +7,12 @@ from collections.abc import AsyncIterator, Callable
7
7
  from typing import Any, Generic, TypeVar
8
8
 
9
9
  from pydantic import BaseModel
10
- from typing_extensions import Unpack
11
10
 
12
11
  from ._client import Piece, carrier_name, piece, request, settle, token_of, url_of
13
12
  from ._errors import CarrierError, CmdopError
14
13
  from ._sealing import Sealing
15
14
  from .carriers import AsyncCarrier, AsyncHttpCarrier, Json
16
15
  from .carriers._carrier import is_answer
17
- from .generated import args as a
18
- from .generated import models as m
19
16
  from .generated.tools import AsyncTools
20
17
 
21
18
  T = TypeVar("T", bound=BaseModel)
@@ -76,13 +73,8 @@ class AsyncMachine(AsyncTools):
76
73
  async def _tool(self, name: str, args: dict[str, Any], out: type[T], deadline: float | None) -> T:
77
74
  return out.model_validate(await self._client.call(name, args, machine=self.name, deadline=deadline))
78
75
 
79
- async def run(self, command: str, /, *, deadline: float | None = None, **args: Unpack[a.ExecRunArgs]) -> m.ExecRunOut:
80
- """`exec_run` with a shell command line."""
81
- return await self.exec_run(deadline=deadline, **{**args, "command": command})
82
-
83
- def stream(self, command: str, /, *, deadline: float | None = None, **args: Unpack[a.ExecRunArgs]) -> AsyncRun[m.ExecRunOut]:
84
- """`exec_run` with its output as it comes."""
85
- return self._client.stream("exec_run", {**args, "command": command}, machine=self.name, deadline=deadline, out=m.ExecRunOut)
76
+ def _stream(self, name: str, args: dict[str, Any], out: type[T], deadline: float | None) -> AsyncRun[T]:
77
+ return self._client.stream(name, args, machine=self.name, deadline=deadline, out=out)
86
78
 
87
79
 
88
80
  class AsyncClient:
@@ -13,14 +13,11 @@ from collections.abc import Callable, Iterator
13
13
  from typing import Any, Generic, TypeVar
14
14
 
15
15
  from pydantic import BaseModel
16
- from typing_extensions import Unpack
17
16
 
18
17
  from ._errors import CarrierError, CmdopError
19
18
  from ._sealing import Sealing
20
19
  from .carriers import Carrier, HttpCarrier, Json
21
20
  from .carriers._carrier import is_answer
22
- from .generated import args as a
23
- from .generated import models as m
24
21
  from .generated.call import OutputChunk
25
22
  from .generated.tools import Tools
26
23
 
@@ -149,7 +146,8 @@ class Run(Generic[R]):
149
146
 
150
147
 
151
148
  class Machine(Tools):
152
- """One machine: every tool as a method (`box.fs_read(path=...)`) and two short forms."""
149
+ """One machine: every tool as a method (`box.fs_read(path=...)`), under its group (`box.fs.read(path=...)`), and the
150
+ short forms (`run`, `stream`, `screenshot`), all generated (`generated/tools.py`)."""
153
151
 
154
152
  def __init__(self, client: Client, name: str | None) -> None:
155
153
  self._client = client
@@ -158,13 +156,8 @@ class Machine(Tools):
158
156
  def _tool(self, name: str, args: dict[str, Any], out: type[T], deadline: float | None) -> T:
159
157
  return out.model_validate(self._client.call(name, args, machine=self.name, deadline=deadline))
160
158
 
161
- def run(self, command: str, /, *, deadline: float | None = None, **args: Unpack[a.ExecRunArgs]) -> m.ExecRunOut:
162
- """`exec_run` with a shell command line."""
163
- return self.exec_run(deadline=deadline, **{**args, "command": command})
164
-
165
- def stream(self, command: str, /, *, deadline: float | None = None, **args: Unpack[a.ExecRunArgs]) -> Run[m.ExecRunOut]:
166
- """`exec_run` with its output as it comes."""
167
- return self._client.stream("exec_run", {**args, "command": command}, machine=self.name, deadline=deadline, out=m.ExecRunOut)
159
+ def _stream(self, name: str, args: dict[str, Any], out: type[T], deadline: float | None) -> Run[T]:
160
+ return self._client.stream(name, args, machine=self.name, deadline=deadline, out=out)
168
161
 
169
162
 
170
163
  class Client:
@@ -0,0 +1,42 @@
1
+ """A screenshot as bytes: the machine answers base64 PNG inside the JSON; this decodes it (the twin of `screen.ts`)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ from dataclasses import dataclass
7
+
8
+ from .generated import models as m
9
+
10
+ _MIME = {"png": "image/png", "jpeg": "image/jpeg", "jpg": "image/jpeg", "webp": "image/webp"}
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class DecodedImage:
15
+ """A decoded picture: `data` is the encoded file (PNG), ready to write to a `.png`."""
16
+
17
+ data: bytes
18
+ mime: str
19
+ width: int
20
+ height: int
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class Screenshot:
25
+ """What `box.screenshot()` returns. Pixel coordinates of every pointer tool are pixels of `image` (see `geometry`)."""
26
+
27
+ image: DecodedImage
28
+ geometry: m.Geometry
29
+ audit_id: str
30
+ """Id of the audit line and the saved copy on the machine."""
31
+
32
+
33
+ def decode_image(image: m.Image) -> DecodedImage:
34
+ """Decodes the base64 `data` of a machine picture. Raises on a format this SDK does not know, rather than guess."""
35
+ mime = _MIME.get(image.format.lower())
36
+ if mime is None:
37
+ raise ValueError(f"unknown image format {image.format!r}")
38
+ return DecodedImage(base64.b64decode(image.data), mime, image.width, image.height)
39
+
40
+
41
+ def to_screenshot(out: m.ScreenCaptureOut) -> Screenshot:
42
+ return Screenshot(decode_image(out.image), out.geometry, out.audit_id)
@@ -0,0 +1 @@
1
+ # Generated from cmdop/crates/tools/tools.schema.json (sha256 72ba780fabadfafb, cmdop 0.1.10) by exports/sdk/gen/gen.ts. Do not edit.
@@ -1,4 +1,4 @@
1
- # Generated from cmdop/crates/tools/tools.schema.json (sha256 459e32fe9bbff178, cmdop 0.1.9) by exports/sdk/gen/gen.ts. Do not edit.
1
+ # Generated from cmdop/crates/tools/tools.schema.json (sha256 72ba780fabadfafb, cmdop 0.1.10) by exports/sdk/gen/gen.ts. Do not edit.
2
2
  # Types by datamodel-code-generator==0.30.2.
3
3
 
4
4
  from __future__ import annotations
@@ -51,7 +51,8 @@ class ExecRunArgs(TypedDict):
51
51
  """
52
52
  env: NotRequired[dict[str, str]]
53
53
  """
54
- Extra environment variables for this command.
54
+ Extra environment variables for this command. It gets these and a small base (PATH, HOME,
55
+ USER, SHELL, the locale, the desktop session); nothing else of cmdop's own environment.
55
56
  """
56
57
  stdin: NotRequired[str | None]
57
58
  """
@@ -59,18 +60,21 @@ class ExecRunArgs(TypedDict):
59
60
  """
60
61
  timeout_secs: NotRequired[int | None]
61
62
  """
62
- Seconds before the command is stopped (default 120, at most 600).
63
+ Seconds before the command and its whole process group are stopped (default 120, at most
64
+ 600). Long work goes to `task_start`.
63
65
  """
64
66
 
65
67
 
66
68
  class FsDeleteArgs(TypedDict):
67
69
  path: str
68
70
  """
69
- File or folder on the machine. Absolute, or relative to the user's home folder.
71
+ File or folder on the machine. Absolute, or relative to the user's home folder. The home
72
+ folder, the file system root and the machine's allowed roots themselves are refused.
70
73
  """
71
74
  permanent: NotRequired[bool]
72
75
  """
73
- Remove for good instead of moving to the trash. Only where the trash cannot take it.
76
+ Remove for good instead of moving to the trash (macOS ~/.Trash, Linux the freedesktop
77
+ trash). Only where the trash cannot take it.
74
78
  """
75
79
  recursive: NotRequired[bool]
76
80
  """
@@ -81,7 +85,8 @@ class FsDeleteArgs(TypedDict):
81
85
  class FsEditArgs(TypedDict):
82
86
  expect_sha256: NotRequired[str | None]
83
87
  """
84
- Refuse unless the file's SHA-256 is this.
88
+ Refuse unless the file's SHA-256 is this: from `fs_stat` with hash=true, or the sha256 the
89
+ last write of it returned.
85
90
  """
86
91
  new: str
87
92
  """
@@ -89,7 +94,8 @@ class FsEditArgs(TypedDict):
89
94
  """
90
95
  old: str
91
96
  """
92
- The exact text to replace, whitespace included. Must occur once, unless `replace_all`.
97
+ The exact text to replace, whitespace included; no regular expressions, no fuzzy matching.
98
+ Must occur once, unless `replace_all`.
93
99
  """
94
100
  path: str
95
101
  """
@@ -160,7 +166,8 @@ class FsSearchArgs(TypedDict):
160
166
  """
161
167
  root: str
162
168
  """
163
- Folder to search under. Absolute, or relative to the user's home folder.
169
+ Folder to search under. Absolute, or relative to the user's home folder. Symlinks are not
170
+ followed; folders holding keys and credentials are skipped.
164
171
  """
165
172
 
166
173
 
@@ -200,7 +207,8 @@ class FsWriteArgs(TypedDict):
200
207
  """
201
208
  path: str
202
209
  """
203
- File on the machine. Absolute, or relative to the user's home folder.
210
+ File on the machine. Absolute, or relative to the user's home folder. An existing file
211
+ keeps its permissions.
204
212
  """
205
213
 
206
214
 
@@ -1,4 +1,4 @@
1
- # Generated from cmdop/crates/tools/tools.schema.json (sha256 459e32fe9bbff178, cmdop 0.1.9) by exports/sdk/gen/gen.ts. Do not edit.
1
+ # Generated from cmdop/crates/tools/tools.schema.json (sha256 72ba780fabadfafb, cmdop 0.1.10) by exports/sdk/gen/gen.ts. Do not edit.
2
2
  # Types by datamodel-code-generator==0.30.2.
3
3
 
4
4
  from __future__ import annotations
@@ -93,7 +93,8 @@ class ToolError(BaseModel):
93
93
  ] = Field(..., title="ErrorCode")
94
94
  """
95
95
  `denied`: The grant or the machine's ceiling does not allow it.
96
- `unknown_tool`: This machine does not have the tool (an older program).
96
+ `unknown_tool`: This machine does not have the tool: its program is older, or a screen tool has no screen
97
+ there. A tool the machine's own limit leaves out is `denied` instead.
97
98
  `bad_args`: The arguments do not match the tool's schema.
98
99
  `not_found`: The path or the thing named does not exist.
99
100
  `busy`: The machine runs too many calls already.
@@ -1,4 +1,4 @@
1
- # Generated from cmdop/crates/tools/tools.schema.json (sha256 459e32fe9bbff178, cmdop 0.1.9) by exports/sdk/gen/gen.ts. Do not edit.
1
+ # Generated from cmdop/crates/tools/tools.schema.json (sha256 72ba780fabadfafb, cmdop 0.1.10) by exports/sdk/gen/gen.ts. Do not edit.
2
2
  # Types by datamodel-code-generator==0.30.2.
3
3
 
4
4
  from __future__ import annotations