fromargs 0.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.
@@ -0,0 +1,23 @@
1
+ # Python
2
+ __pycache__/
3
+ *.pyc
4
+ .venv/
5
+
6
+ # OS / editor
7
+ .DS_Store
8
+ *.swp
9
+ .idea/
10
+ .vscode/
11
+
12
+ # Workflow scratch (age/cure/press reports, planning notes)
13
+ .cheese/
14
+ .context/
15
+
16
+ # Skill-creator iteration workspaces (eval runs, benchmarks, viewer HTML)
17
+ skills/*-workspace/
18
+
19
+ # file-handler skill artifact tree (local scratch space)
20
+ .skillz/
21
+
22
+ # Serena MCP — machine-local; not tracked
23
+ .serena/
fromargs-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Paul Sorensen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.5
2
+ Name: fromargs
3
+ Version: 0.1.0
4
+ Summary: Self-healing Cyclopts CLI helpers for agent-friendly command lines.
5
+ Project-URL: Homepage, https://github.com/paulnsorensen/skillz-that-grillz/tree/main/lib/fromargs
6
+ Project-URL: Source, https://github.com/paulnsorensen/skillz-that-grillz/tree/main/lib/fromargs
7
+ Project-URL: Issues, https://github.com/paulnsorensen/skillz-that-grillz/issues
8
+ Author-email: Paul Sorensen <paulnsorensen@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,cli,cyclopts,json
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: cyclopts<5,>=4.25.3
21
+ Description-Content-Type: text/markdown
22
+
23
+ # fromargs
24
+
25
+ `fromargs` is a self-healing, agent-friendly wrapper around
26
+ [Cyclopts](https://cyclopts.readthedocs.io/). It composes one `cyclopts.App`,
27
+ forces every command's return value to JSON, and repairs the argv mistakes an
28
+ LLM agent tends to make, without ever guessing at intent it cannot verify.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ uv add fromargs
34
+ # or
35
+ pip install fromargs
36
+ ```
37
+
38
+ `fromargs` pins `cyclopts>=4.25.3,<5`; it does not yet track Cyclopts 5.
39
+
40
+ ## Quick start
41
+
42
+ ```python
43
+ from typing import Annotated
44
+
45
+ import fromargs
46
+
47
+ app = fromargs.App("cheese-cave", help="Track wheels of cheese as they ripen.")
48
+
49
+
50
+ @app.command
51
+ def age(
52
+ name: str,
53
+ *,
54
+ weeks: Annotated[int, fromargs.Parameter(help="Number of weeks to age.")],
55
+ dry_run: bool = False,
56
+ ) -> dict[str, object]:
57
+ """Age one wheel for more weeks."""
58
+ if weeks < 1:
59
+ raise fromargs.CliError(f"--weeks must be at least 1, got {weeks}")
60
+ return {"name": name, "weeks": weeks, "dry_run": dry_run}
61
+
62
+
63
+ if __name__ == "__main__":
64
+ app.main()
65
+ ```
66
+
67
+ ```console
68
+ $ python cheese_cave.py age brie --weeks 2
69
+ {
70
+ "name": "brie",
71
+ "weeks": 2,
72
+ "dry_run": false
73
+ }
74
+ ```
75
+
76
+ See `examples/cheese_cave.py` for a fuller example, with a command group and
77
+ a truncated list result.
78
+
79
+ ## Output contract
80
+
81
+ - A handler returns data, not text. A non-`None` return value prints as one
82
+ JSON document on stdout, then the process exits `0`.
83
+ - A `None` return value means exit `0` with no stdout.
84
+ - Every error is one JSON line on stderr: `{"error": <message>, "exit_code": <n>}`.
85
+ Raise `fromargs.CliError(message)` for exit code `2`, or
86
+ `fromargs.contract_error(exc, context=...)` to wrap a caught exception at
87
+ exit code `3`. An unhandled Cyclopts parse error also reports at exit
88
+ code `2`.
89
+ - A quote-split repair (below) prints one plain-text `note:` line on stderr;
90
+ it never changes stdout or the exit code.
91
+
92
+ ## Global flags
93
+
94
+ `fromargs` strips two flags from argv before Cyclopts ever sees them, from
95
+ anywhere before the end-of-options marker:
96
+
97
+ - `--json` is a no-op. Agents that append it by habit get plain JSON either
98
+ way, so the flag costs nothing and fails nothing.
99
+ - `--full` turns off result truncation for the current call.
100
+
101
+ Neither flag reaches a handler, and neither is a real Cyclopts option.
102
+
103
+ ## `limit`
104
+
105
+ `@app.command(limit=n)` truncates a sequence result to its first `n` items,
106
+ unless the caller passes `--full`. Truncation prints a `note:` line on
107
+ stderr and never applies to a mapping or a string. `App.default` accepts the
108
+ same `limit` keyword.
109
+
110
+ ## `App.default`
111
+
112
+ `@app.default` (bare or called, matching `@app.command`) registers the
113
+ handler that runs when argv names no subcommand at that app or group level.
114
+ It is rejected at registration if it declares a `json` or `full` parameter,
115
+ the same rule `@app.command` enforces. Registering a second default on the
116
+ same app or group raises `ValueError`.
117
+
118
+ ## Self-healing
119
+
120
+ An agent's shell layer sometimes merges two arguments into one quoted token,
121
+ for example `--weeks "2 --dry-run"` instead of `--weeks 2 --dry-run`. When
122
+ Cyclopts rejects an argv, `fromargs` shell-splits each option's value once
123
+ and re-parses. It applies a split only when:
124
+
125
+ - the split has at least two pieces, and one looks like a flag; and
126
+ - the option can take a split value (not a boolean flag, not free-text `str`
127
+ or `Path`); and
128
+ - exactly one split candidate among all options parses cleanly.
129
+
130
+ It prints `note: split quoted argument ... into ...` on stderr when it
131
+ applies a repair. `fromargs` refuses to guess when a split is ambiguous
132
+ (more than one candidate parses), when the option takes free text, or for
133
+ any token after the end-of-options marker (`--` by default). In every
134
+ refusal case, the original parse error is reported unchanged.
135
+
136
+ ## Version resolution
137
+
138
+ `fromargs.App(name)` reports the version of the *calling* module, not the
139
+ version of `fromargs` itself. It resolves, in order:
140
+
141
+ 1. an explicit `version=` argument, if the caller passes one;
142
+ 2. `importlib.metadata.version(...)` for the caller's installed distribution;
143
+ 3. the caller module's `__version__` attribute;
144
+ 4. `"0.0.0"`, if none of the above resolve.
145
+
146
+ `App.group(name, version=..., **cyclopts_kwargs)` forwards every extra
147
+ keyword, including `version`, to the nested `cyclopts.App`, so a group can
148
+ report its own version independently of the root app.
@@ -0,0 +1,126 @@
1
+ # fromargs
2
+
3
+ `fromargs` is a self-healing, agent-friendly wrapper around
4
+ [Cyclopts](https://cyclopts.readthedocs.io/). It composes one `cyclopts.App`,
5
+ forces every command's return value to JSON, and repairs the argv mistakes an
6
+ LLM agent tends to make, without ever guessing at intent it cannot verify.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ uv add fromargs
12
+ # or
13
+ pip install fromargs
14
+ ```
15
+
16
+ `fromargs` pins `cyclopts>=4.25.3,<5`; it does not yet track Cyclopts 5.
17
+
18
+ ## Quick start
19
+
20
+ ```python
21
+ from typing import Annotated
22
+
23
+ import fromargs
24
+
25
+ app = fromargs.App("cheese-cave", help="Track wheels of cheese as they ripen.")
26
+
27
+
28
+ @app.command
29
+ def age(
30
+ name: str,
31
+ *,
32
+ weeks: Annotated[int, fromargs.Parameter(help="Number of weeks to age.")],
33
+ dry_run: bool = False,
34
+ ) -> dict[str, object]:
35
+ """Age one wheel for more weeks."""
36
+ if weeks < 1:
37
+ raise fromargs.CliError(f"--weeks must be at least 1, got {weeks}")
38
+ return {"name": name, "weeks": weeks, "dry_run": dry_run}
39
+
40
+
41
+ if __name__ == "__main__":
42
+ app.main()
43
+ ```
44
+
45
+ ```console
46
+ $ python cheese_cave.py age brie --weeks 2
47
+ {
48
+ "name": "brie",
49
+ "weeks": 2,
50
+ "dry_run": false
51
+ }
52
+ ```
53
+
54
+ See `examples/cheese_cave.py` for a fuller example, with a command group and
55
+ a truncated list result.
56
+
57
+ ## Output contract
58
+
59
+ - A handler returns data, not text. A non-`None` return value prints as one
60
+ JSON document on stdout, then the process exits `0`.
61
+ - A `None` return value means exit `0` with no stdout.
62
+ - Every error is one JSON line on stderr: `{"error": <message>, "exit_code": <n>}`.
63
+ Raise `fromargs.CliError(message)` for exit code `2`, or
64
+ `fromargs.contract_error(exc, context=...)` to wrap a caught exception at
65
+ exit code `3`. An unhandled Cyclopts parse error also reports at exit
66
+ code `2`.
67
+ - A quote-split repair (below) prints one plain-text `note:` line on stderr;
68
+ it never changes stdout or the exit code.
69
+
70
+ ## Global flags
71
+
72
+ `fromargs` strips two flags from argv before Cyclopts ever sees them, from
73
+ anywhere before the end-of-options marker:
74
+
75
+ - `--json` is a no-op. Agents that append it by habit get plain JSON either
76
+ way, so the flag costs nothing and fails nothing.
77
+ - `--full` turns off result truncation for the current call.
78
+
79
+ Neither flag reaches a handler, and neither is a real Cyclopts option.
80
+
81
+ ## `limit`
82
+
83
+ `@app.command(limit=n)` truncates a sequence result to its first `n` items,
84
+ unless the caller passes `--full`. Truncation prints a `note:` line on
85
+ stderr and never applies to a mapping or a string. `App.default` accepts the
86
+ same `limit` keyword.
87
+
88
+ ## `App.default`
89
+
90
+ `@app.default` (bare or called, matching `@app.command`) registers the
91
+ handler that runs when argv names no subcommand at that app or group level.
92
+ It is rejected at registration if it declares a `json` or `full` parameter,
93
+ the same rule `@app.command` enforces. Registering a second default on the
94
+ same app or group raises `ValueError`.
95
+
96
+ ## Self-healing
97
+
98
+ An agent's shell layer sometimes merges two arguments into one quoted token,
99
+ for example `--weeks "2 --dry-run"` instead of `--weeks 2 --dry-run`. When
100
+ Cyclopts rejects an argv, `fromargs` shell-splits each option's value once
101
+ and re-parses. It applies a split only when:
102
+
103
+ - the split has at least two pieces, and one looks like a flag; and
104
+ - the option can take a split value (not a boolean flag, not free-text `str`
105
+ or `Path`); and
106
+ - exactly one split candidate among all options parses cleanly.
107
+
108
+ It prints `note: split quoted argument ... into ...` on stderr when it
109
+ applies a repair. `fromargs` refuses to guess when a split is ambiguous
110
+ (more than one candidate parses), when the option takes free text, or for
111
+ any token after the end-of-options marker (`--` by default). In every
112
+ refusal case, the original parse error is reported unchanged.
113
+
114
+ ## Version resolution
115
+
116
+ `fromargs.App(name)` reports the version of the *calling* module, not the
117
+ version of `fromargs` itself. It resolves, in order:
118
+
119
+ 1. an explicit `version=` argument, if the caller passes one;
120
+ 2. `importlib.metadata.version(...)` for the caller's installed distribution;
121
+ 3. the caller module's `__version__` attribute;
122
+ 4. `"0.0.0"`, if none of the above resolve.
123
+
124
+ `App.group(name, version=..., **cyclopts_kwargs)` forwards every extra
125
+ keyword, including `version`, to the nested `cyclopts.App`, so a group can
126
+ report its own version independently of the root app.
@@ -0,0 +1,97 @@
1
+ """cheese-cave: an example agent-friendly CLI built on fromargs.
2
+
3
+ The CLI tracks wheels of cheese as they ripen. Run it from the repository root:
4
+
5
+ uv run --project lib/fromargs python lib/fromargs/examples/cheese_cave.py wheels list
6
+
7
+ Agents often send malformed argv. Each call below still runs the intended
8
+ command, and ``run`` prints one ``note:`` line on stderr for each repair:
9
+
10
+ cheese_cave.py --json wheels list # --json is a no-op, dropped
11
+ cheese_cave.py age brie --weeks "2 --dry-run" # splits the merged argument
12
+ cheese_cave.py --json age brie --weeks "2 --dry-run" # both repairs
13
+
14
+ Cyclopts itself binds ``--dry_run`` to ``--dry-run``. It also answers a
15
+ misspelled command such as ``wheels lst`` with ``Did you mean "list"?``.
16
+ """
17
+
18
+ import sys
19
+ from dataclasses import dataclass
20
+
21
+ import fromargs
22
+
23
+ LIST_LIMIT = 3
24
+
25
+
26
+ @dataclass
27
+ class Wheel:
28
+ name: str
29
+ style: str
30
+ weeks: int
31
+
32
+
33
+ def starter_cave() -> dict[str, Wheel]:
34
+ """Return a new cave with four wheels, keyed by name."""
35
+ wheels = [
36
+ Wheel("brie", "bloomy", 4),
37
+ Wheel("comte", "alpine", 52),
38
+ Wheel("gouda", "washed-curd", 26),
39
+ Wheel("stilton", "blue", 12),
40
+ ]
41
+ return {wheel.name: wheel for wheel in wheels}
42
+
43
+
44
+ def build_app(cave: dict[str, Wheel]) -> fromargs.App:
45
+ """Build the cheese-cave CLI over ``cave``; commands change it in place."""
46
+ app = fromargs.App("cheese-cave", help="Track wheels of cheese as they ripen.")
47
+ wheels = app.group("wheels", help="Inspect the wheels in the cave.")
48
+
49
+ @wheels.command(name="list", limit=LIST_LIMIT)
50
+ def list_wheels() -> list[Wheel]:
51
+ """List the wheels, oldest first."""
52
+ return sorted(cave.values(), key=lambda wheel: -wheel.weeks)
53
+
54
+ @wheels.command
55
+ def show(name: str) -> Wheel:
56
+ """Show one wheel."""
57
+ return _find(cave, name)
58
+
59
+ @app.command
60
+ def age(name: str, *, weeks: int, dry_run: bool = False) -> dict[str, object]:
61
+ """Age one wheel for more weeks."""
62
+ if weeks < 1:
63
+ raise fromargs.CliError(f"--weeks must be at least 1, got {weeks}")
64
+ wheel = _find(cave, name)
65
+ total = wheel.weeks + weeks
66
+ if not dry_run:
67
+ wheel.weeks = total
68
+ return {"name": wheel.name, "weeks": total, "dry_run": dry_run}
69
+
70
+ @app.command
71
+ def load(record: str) -> Wheel:
72
+ """Add a wheel from a ``name:style:weeks`` record."""
73
+ try:
74
+ name, style, weeks = record.split(":")
75
+ wheel = Wheel(name, style, int(weeks))
76
+ except ValueError as exc:
77
+ raise fromargs.contract_error(exc, context=f"record {record!r}") from exc
78
+ cave[wheel.name] = wheel
79
+ return wheel
80
+
81
+ return app
82
+
83
+
84
+ def _find(cave: dict[str, Wheel], name: str) -> Wheel:
85
+ """Return the named wheel, or fail with the names an agent can retry."""
86
+ if name not in cave:
87
+ known = ", ".join(sorted(cave))
88
+ raise fromargs.CliError(f"unknown wheel {name!r}; known wheels: {known}")
89
+ return cave[name]
90
+
91
+
92
+ def main(argv: list[str] | None = None) -> int:
93
+ return build_app(starter_cave()).run(argv)
94
+
95
+
96
+ if __name__ == "__main__":
97
+ sys.exit(main())
@@ -0,0 +1,53 @@
1
+ [project]
2
+ name = "fromargs"
3
+ version = "0.1.0"
4
+ description = "Self-healing Cyclopts CLI helpers for agent-friendly command lines."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "Paul Sorensen", email = "paulnsorensen@gmail.com" }]
10
+ keywords = ["cli", "cyclopts", "agent", "json"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Programming Language :: Python :: 3.11",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Typing :: Typed",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ ]
20
+ dependencies = ["cyclopts>=4.25.3,<5"]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/paulnsorensen/skillz-that-grillz/tree/main/lib/fromargs"
24
+ Source = "https://github.com/paulnsorensen/skillz-that-grillz/tree/main/lib/fromargs"
25
+ Issues = "https://github.com/paulnsorensen/skillz-that-grillz/issues"
26
+
27
+ [dependency-groups]
28
+ dev = ["pytest>=8", "basedpyright==1.40.1"]
29
+
30
+ [build-system]
31
+ requires = ["hatchling>=1.27.0"]
32
+ build-backend = "hatchling.build"
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["src/fromargs"]
36
+
37
+ [tool.hatch.build.targets.sdist]
38
+ exclude = [
39
+ ".venv",
40
+ "**/__pycache__",
41
+ "**/.pytest_cache",
42
+ ]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ pythonpath = ["examples"]
47
+ markers = ["ac(id): ties a test to an acceptance-criterion ID"]
48
+ addopts = "--strict-markers"
49
+
50
+ [tool.basedpyright]
51
+ pythonVersion = "3.11"
52
+ include = ["src", "tests", "examples"]
53
+ extraPaths = ["examples"]
@@ -0,0 +1,22 @@
1
+ """Self-healing Cyclopts CLI helpers for agent-friendly command lines.
2
+
3
+ ``App`` composes a ``cyclopts.App``. Register a command with ``@app.command``
4
+ and a nested command group with ``app.group(name)``. A handler returns data,
5
+ not text: ``run`` parses argv once, invokes one handler, and prints the
6
+ return value as one JSON document on stdout. ``None`` means no stdout and
7
+ exit 0.
8
+
9
+ ``run`` strips a bare ``--json`` or ``--full`` token from anywhere before the
10
+ end-of-options marker: ``--json`` is a no-op accepted for agents that pass it
11
+ by habit, and ``--full`` turns off result truncation. It also repairs one
12
+ verified shell-merged argument before it reports an error, and announces
13
+ each repair on stderr. Every error is one JSON line on stderr:
14
+ ``{"error": <message>, "exit_code": <n>}``. There is no JSON input mode.
15
+ """
16
+
17
+ from cyclopts import Group, Parameter
18
+
19
+ from fromargs._app import App
20
+ from fromargs._errors import CliError, contract_error
21
+
22
+ __all__ = ["App", "CliError", "Group", "Parameter", "contract_error"]