-
Notifications
You must be signed in to change notification settings - Fork 0
Rectify: CmdSpec Argument Ordering Structural Immunity #3341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Trecek
merged 8 commits into
develop
from
autoskillit-order-session-sits-idle-tools-variadic-flag-cons/3285
May 30, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33def5b
test: add failing tests for CmdSpec argument ordering immunity
Trecek 9bce243
feat: structural immunity for CmdSpec argument ordering
Trecek ce96b45
fix: re-export assert_interactive_ordering through public API and fixβ¦
Trecek d911eb8
fix(review): use builder.positional(sid) for NamedResume session_id aβ¦
Trecek 4f62e17
fix(review): add empty binary validation guard to CmdBuilder.__init__
Trecek 0177f0b
fix(review): use backend-specific flag constant and assert presence iβ¦
Trecek f08b733
fix(review): update resume tests to check origin.positional instead oβ¦
Trecek 81ab78e
fix(review): extract _collect_imported_names helper to deduplicate ASβ¦
Trecek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """Typed command builder that enforces positional-before-variadic ordering by construction.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
|
|
||
| from autoskillit.core import CmdOrigin, CmdSpec | ||
|
|
||
| __all__ = ["CmdBuilder", "CmdOrderingError"] | ||
|
|
||
|
|
||
| class CmdOrderingError(ValueError): | ||
| """Raised when a positional argument is added after a variadic pair.""" | ||
|
|
||
|
|
||
| class CmdBuilder: | ||
| """Build a CmdSpec with structural enforcement of argument ordering. | ||
|
|
||
| Sections are assembled in a fixed order: | ||
| binary β mode_flags β kv_flags β positional β variadic_pairs | ||
|
|
||
| Calling ``positional()`` after ``variadic_pair()`` raises ``CmdOrderingError`` | ||
| immediately, making argument-ordering bugs impossible by construction. | ||
| """ | ||
|
|
||
| def __init__(self, binary: str) -> None: | ||
| if not binary: | ||
| raise ValueError("binary must be a non-empty string") | ||
| self._binary = binary | ||
| self._mode_flags: list[str] = [] | ||
| self._kv_flags: list[tuple[str, str]] = [] | ||
| self._positional: list[str] = [] | ||
| self._variadic_pairs: list[tuple[str, str]] = [] | ||
| self._has_variadic = False | ||
|
|
||
| def mode_flag(self, flag: str) -> CmdBuilder: | ||
| self._mode_flags.append(flag) | ||
| return self | ||
|
|
||
| def kv_flag(self, flag: str, value: str) -> CmdBuilder: | ||
| self._kv_flags.append((flag, value)) | ||
| return self | ||
|
|
||
| def positional(self, value: str) -> CmdBuilder: | ||
| if self._has_variadic: | ||
| raise CmdOrderingError( | ||
| f"Cannot add positional arg {value!r} after variadic pairs have been added. " | ||
| "Positional args must precede all variadic flag pairs." | ||
| ) | ||
| self._positional.append(value) | ||
| return self | ||
|
|
||
| def variadic_pair(self, flag: str, value: str) -> CmdBuilder: | ||
| self._variadic_pairs.append((flag, value)) | ||
| self._has_variadic = True | ||
| return self | ||
|
|
||
| def build(self, env: Mapping[str, str] | None = None, cwd: str = "") -> CmdSpec: | ||
| cmd: list[str] = [self._binary] | ||
| cmd.extend(self._mode_flags) | ||
| for flag, value in self._kv_flags: | ||
| cmd.extend([flag, value]) | ||
| cmd.extend(self._positional) | ||
| for flag, value in self._variadic_pairs: | ||
| cmd.extend([flag, value]) | ||
| origin = CmdOrigin( | ||
| binary=self._binary, | ||
| mode_flags=tuple(self._mode_flags), | ||
| kv_flags=tuple(self._kv_flags), | ||
| positional=tuple(self._positional), | ||
| variadic_pairs=tuple(self._variadic_pairs), | ||
| ) | ||
| return CmdSpec( | ||
| cmd=tuple(cmd), | ||
| env=env if env is not None else {}, | ||
| cwd=cwd, | ||
| origin=origin, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[warning] cohesion: NON_VARIADIC_CLAUDE_FLAGS (core/types/_type_enums.py) and _CLAUDE_VALUE_BEARING_FLAGS (_headless_helpers.py) both classify ClaudeFlags members by argument-taking behavior but are defined separately with overlapping intent and inconsistent membership. The flag-classification vocabulary is split across two layers with neither referencing the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid observation β flagged for design decision.
NON_VARIADIC_CLAUDE_FLAGSand_CLAUDE_VALUE_BEARING_FLAGSoverlap in intent but serve different validation gates. Unification requires deciding on a single taxonomy for flag properties.