Skip to content

API Reference parrot.tools.optimizations.models

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.optimizations.models

View source

Pydantic contracts for the tool-optimizations toolkits (FEAT-543).

This module holds every typed contract shared by :class:LocalGitToolkit, :class:BoundedSourceToolkit and :class:TargetedWriterToolkit:

  • Operation results (:class:StepResult, :class:OperationError, :class:OperationResult).
  • Bounded-reader results (:class:SourceInfo, :class:SourceResult).
  • Delegation contracts (:class:ReferenceSlice, :class:TargetFile, :class:DelegationPacket, :class:WriterLimits, :class:PatchManifest).
  • Per-tool argument models, used both as @tool_schema schemas and as the raw-argument validation seam in :meth:~parrot.tools.optimizations.base.OptimizationToolkitBase._pre_execute.

Every model sets extra="forbid": the argument models see raw MCP input (MCPToolAdapter.execute calls tool._execute(**arguments) directly), so unknown keys must be rejected rather than silently dropped.

Class DelegationPacket

The complete, already-decided implementation contract for one TASK.

design_complete is an eligibility declaration, not proof of correctness: this model checks structural completeness, while the thinking model verifies semantics.

Attributes:

Attribute Type Description
schema_version Literal[1] Always 1 in v1.
task_id str The owning task identifier (TASK-<NNN>).
spec_path ShortStr Repo-relative path of the governing spec.
design_complete Literal[True] Must be True; a packet is otherwise ineligible.
targets List[TargetFile] The approved file scope (at least one, unique paths).
references List[ReferenceSlice] Hashed bounded excerpts supplied as read-only context.
implementation_blocks List[ShortStr] Labels of the decided code blocks in the TASK.
acceptance_criteria List[ShortStr] The criteria the change must satisfy.
validation_commands List[List[ShortStr]] argv lists owned by the SDD workflow. No command from a model response is ever executed.
limits WriterLimits The budgets for this delegation.

Class GitFetchArgs

Arguments for git_fetch.

Attributes:

Attribute Type Description
remote ShortStr
branch ShortStr
recent int

Class GitPreflightArgs

Arguments for git_preflight (none).

Class GitPrepareFilesArgs

Arguments for git_prepare_files.

Attributes:

Attribute Type Description
paths List[ShortStr]

Class GitPullArgs

Arguments for git_pull.

Attributes:

Attribute Type Description
remote ShortStr
branch Optional[ShortStr]

Class GitPushArgs

Arguments for git_push.

Attributes:

Attribute Type Description
remote ShortStr
branch Optional[ShortStr]

Class GitRecentArgs

Arguments for git_recent.

Attributes:

Attribute Type Description
ref ShortStr
limit int

Class OperationError

A structured, machine-readable operation failure.

Attributes:

Attribute Type Description
code str A snake_case error code (e.g. range_required, path_outside_root, secret_file, unrelated_staged).
message str A short human-readable explanation.
details Dict[str, Any] Optional structured context for the caller.

Class OperationResult

The bounded domain result returned by every optimization tool.

status is the domain outcome; the MCP isError flag is reserved for argument rejection and crashes.

Attributes:

Attribute Type Description
status Literal['ok', 'error', 'uncertain'] ok, error or uncertain (e.g. a push that timed out after transmission, whose remote effect is unknown).
operation str The tool/method name that produced this result.
data Dict[str, Any] The bounded operation payload.
error Optional[OperationError] Structured failure details when status is not ok.
steps List[StepResult] Per-step outcomes, in execution order.
truncated bool True when content was reduced to fit the byte budget.
diagnostic_path Optional[str] Optional repo-relative path to a retained diagnostic.
elapsed_ms int Wall-clock duration of the operation, in milliseconds.

Class PatchManifest

Provenance and validation state for one generated patch artifact.

Attributes:

Attribute Type Description
artifact_id ArtifactIdStr Opaque identifier of the stored artifact directory.
task_id str The originating task identifier.
task_path ShortStr Repo-relative path of the TASK file, so an apply can re-validate the very same contract this patch came from.
packet_sha256 Sha256Str Hash of the canonical delegation packet.
patch_sha256 Sha256Str Hash of the normalized unified patch.
before_hashes Dict[str, Optional[str]] Per-target baseline hash; None means "must be absent".
after_hashes Dict[str, str] Per-target hash after staged application.
allowed_paths List[str] The approved target scope.
configured_model str The model identity requested by configuration.
actual_model Optional[str] The model identity reported by the provider, if known.
used_fallback bool True when the provider reported a model substitution.
usage Dict[str, Optional[int]] Token usage; None values mean the provider reported nothing (unknown is never recorded as zero).
repairs int Number of repair calls consumed (0 or 1).
elapsed_ms int Wall-clock duration of generation.
validation_state Literal['validated', 'rejected'] validated or rejected.
created_at str ISO-8601 UTC creation timestamp.

Class ReferenceSlice

A hashed, bounded excerpt of an existing file included as context.

Attributes:

Attribute Type Description
path ShortStr Repo-relative POSIX path of the referenced file.
sha256 Sha256Str SHA-256 of the referenced file's bytes, checked for freshness.
start_line int First referenced line, 1-based inclusive.
end_line int Last referenced line, 1-based inclusive.
purpose str Why the delegate needs this excerpt.

Class SourceInfo

Bounded metadata about a source file, with no file content.

Attributes:

Attribute Type Description
path str Repo-relative POSIX path.
sha256 Sha256Str SHA-256 of the on-disk bytes.
size_bytes int On-disk size in bytes.
line_count Optional[int] Exact logical line count, or None when only threshold detection ran (large files short-circuit exact counting).
is_large bool True when either configured threshold is exceeded.
max_lines int The configured line threshold in effect.
large_file_bytes int The configured byte threshold in effect.
range_required bool True when a read must supply both range ends.

Class SourceInfoArgs

Arguments for source_info.

Attributes:

Attribute Type Description
path ShortStr

Class SourceReadArgs

Arguments for source_read.

Both range ends are required together: one coordinate system (1-based inclusive lines) and no offset/limit aliases.

Attributes:

Attribute Type Description
path ShortStr
start_line Optional[int]
end_line Optional[int]
expected_sha256 Optional[Sha256Str]

Class SourceResult

A bounded slice of a source file with an explicit continuation cursor.

Attributes:

Attribute Type Description
path str Repo-relative POSIX path.
sha256 Sha256Str SHA-256 of the whole file's on-disk bytes (the revision).
size_bytes int On-disk size in bytes.
start_line int First returned line, 1-based inclusive.
end_line int Last returned line, 1-based inclusive. 0 with an empty content denotes an empty file.
content str The returned complete lines.
truncated bool True when fewer lines were returned than requested because of the serialized byte budget.
next_line Optional[int] The line to request next, or None at EOF.
eof bool True when the returned range reaches the end of the file.

Class StepResult

The outcome of one independent step inside a composite operation.

Success is never inferred from the last command alone: every step records its own exit code, timeout flag and whether it changed state.

Attributes:

Attribute Type Description
name str The step identifier (e.g. git_status).
exit_code Optional[int] The process exit code, or None when it never ran or timed out.
timed_out bool True when the step exceeded its timeout.
state_changed bool True when the step mutated repository or index state.
stdout str Bounded standard output.
stderr str Bounded standard error.
truncated bool True when stdout/stderr were clipped to fit a budget.

Class TargetFile

One file the delegate is allowed to create or modify.

Attributes:

Attribute Type Description
path ShortStr Repo-relative POSIX path.
action Literal['create', 'modify'] create (the file must be absent) or modify.
expected_sha256 Optional[Sha256Str] Required for modify (the baseline revision); must be None for create, whose precondition is absence.
planned_changes str The already-decided change description.
blocks List[ShortStr] Identifiers of the labelled TASK code blocks that specify this file's implementation. At least one is required.

Class WriterApplyArgs

Arguments for writer_apply.

Attributes:

Attribute Type Description
artifact_id ArtifactIdStr
reviewed_sha256 Sha256Str

Class WriterGenerateArgs

Arguments for writer_generate.

Attributes:

Attribute Type Description
task_path ShortStr

Class WriterLimits

Hard budgets applied to one delegated generation operation.

Attributes:

Attribute Type Description
max_packet_bytes int Maximum serialized delegation-packet size.
max_context_bytes int Maximum size of the locally built prompt context.
max_patch_bytes int Maximum size of the generated unified patch.
max_output_tokens int Maximum model output tokens.
generation_deadline_seconds int Overall deadline for the operation, covering transport retries and the optional repair call.
max_repairs Literal[0, 1] At most one repair attempt for a valid packet.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally