delegate-agent-cli 0.11.0__py3-none-any.whl
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.
- delegate_agent/__init__.py +5 -0
- delegate_agent/archived_logs.py +44 -0
- delegate_agent/argv_builders.py +423 -0
- delegate_agent/argv_utils.py +36 -0
- delegate_agent/capability_commands.py +99 -0
- delegate_agent/cli.py +987 -0
- delegate_agent/cli_parser.py +1627 -0
- delegate_agent/command_errors.py +29 -0
- delegate_agent/command_help.py +1264 -0
- delegate_agent/config.py +1117 -0
- delegate_agent/config_commands.py +143 -0
- delegate_agent/constants.py +50 -0
- delegate_agent/describe_payload.py +1018 -0
- delegate_agent/errors.py +32 -0
- delegate_agent/git_utils.py +180 -0
- delegate_agent/harness_events.py +719 -0
- delegate_agent/inspection_commands.py +104 -0
- delegate_agent/isolation.py +316 -0
- delegate_agent/json_types.py +18 -0
- delegate_agent/log_output.py +78 -0
- delegate_agent/private_io.py +109 -0
- delegate_agent/profile_commands.py +42 -0
- delegate_agent/profile_guard.py +116 -0
- delegate_agent/profiles.py +389 -0
- delegate_agent/prompt_instructions.py +39 -0
- delegate_agent/prompt_transport.py +12 -0
- delegate_agent/reasoning.py +916 -0
- delegate_agent/redaction.py +193 -0
- delegate_agent/rendering.py +573 -0
- delegate_agent/request_build.py +1681 -0
- delegate_agent/request_models.py +191 -0
- delegate_agent/retention.py +321 -0
- delegate_agent/run_metadata.py +78 -0
- delegate_agent/run_output_commands.py +645 -0
- delegate_agent/run_registry.py +747 -0
- delegate_agent/run_status.py +300 -0
- delegate_agent/runner.py +1830 -0
- delegate_agent/safe_workspace.py +821 -0
- delegate_agent/snapshot_view.py +229 -0
- delegate_agent/wait_cancel_commands.py +559 -0
- delegate_agent/worktree_commands.py +218 -0
- delegate_agent/worktree_execution.py +654 -0
- delegate_agent/worktree_gc.py +529 -0
- delegate_agent/worktree_mgmt.py +782 -0
- delegate_agent/worktree_records.py +232 -0
- delegate_agent/worktree_remove.py +547 -0
- delegate_agent/worktree_summary.py +242 -0
- delegate_agent/wsl.py +65 -0
- delegate_agent_cli-0.11.0.dist-info/METADATA +325 -0
- delegate_agent_cli-0.11.0.dist-info/RECORD +54 -0
- delegate_agent_cli-0.11.0.dist-info/WHEEL +5 -0
- delegate_agent_cli-0.11.0.dist-info/entry_points.txt +2 -0
- delegate_agent_cli-0.11.0.dist-info/licenses/LICENSE +21 -0
- delegate_agent_cli-0.11.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import TypedDict, cast
|
|
5
|
+
|
|
6
|
+
from delegate_agent import retention as delegate_retention
|
|
7
|
+
from delegate_agent import run_metadata, run_registry
|
|
8
|
+
from delegate_agent.json_types import JsonObject, JsonValue, first_string
|
|
9
|
+
from delegate_agent.redaction import redact_value
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SnapshotView(TypedDict, total=False):
|
|
13
|
+
schema: str
|
|
14
|
+
ok: bool
|
|
15
|
+
runId: str
|
|
16
|
+
alias: str
|
|
17
|
+
harness: str
|
|
18
|
+
cwd: str
|
|
19
|
+
executionCwd: str
|
|
20
|
+
mode: str
|
|
21
|
+
model: str
|
|
22
|
+
status: str
|
|
23
|
+
rawStatus: str
|
|
24
|
+
effectiveStatus: str
|
|
25
|
+
staleReason: str
|
|
26
|
+
pid: int
|
|
27
|
+
exitCode: int
|
|
28
|
+
startedAt: str
|
|
29
|
+
lastActivityAt: str
|
|
30
|
+
finishedAt: str
|
|
31
|
+
current: str
|
|
32
|
+
error: str
|
|
33
|
+
message: str
|
|
34
|
+
plannedBranch: str | None
|
|
35
|
+
plannedExecutionCwd: str | None
|
|
36
|
+
stdoutBytes: int
|
|
37
|
+
stderrBytes: int
|
|
38
|
+
warnings: list[str]
|
|
39
|
+
nextActions: list[str]
|
|
40
|
+
assistantText: str
|
|
41
|
+
assistantTextChars: int
|
|
42
|
+
assistantTextTruncated: bool
|
|
43
|
+
recentEvents: list[JsonObject]
|
|
44
|
+
isolatedWorkspace: bool
|
|
45
|
+
isolationMode: str
|
|
46
|
+
effectiveIsolation: str
|
|
47
|
+
isolationLifecycle: str
|
|
48
|
+
preservedWorkspace: bool
|
|
49
|
+
sourceGitRoot: str
|
|
50
|
+
branch: str
|
|
51
|
+
creationContext: JsonObject
|
|
52
|
+
worktreeStatus: str
|
|
53
|
+
safeWorkspaceMethod: str
|
|
54
|
+
worktreeCleanupCommands: JsonObject
|
|
55
|
+
requestedReasoningEffort: str
|
|
56
|
+
resolvedReasoningEffort: str
|
|
57
|
+
reasoningEffortSource: str
|
|
58
|
+
reasoningCapabilitySource: str
|
|
59
|
+
reasoningTransport: str
|
|
60
|
+
snapshotCommand: str
|
|
61
|
+
completionReport: JsonObject
|
|
62
|
+
completionReportWritten: bool
|
|
63
|
+
completionReportSource: str
|
|
64
|
+
resultQuality: str
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _snapshot_value(snapshot: JsonObject | None, key: str) -> object:
|
|
68
|
+
if snapshot is None:
|
|
69
|
+
return None
|
|
70
|
+
return snapshot.get(key)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _write_status_contract(view: SnapshotView, state: JsonObject | None) -> str | None:
|
|
74
|
+
status = run_registry.status_fields(state)
|
|
75
|
+
raw_status = status.get("rawStatus")
|
|
76
|
+
effective_status = status.get("effectiveStatus")
|
|
77
|
+
display_status = status.get("status")
|
|
78
|
+
stale_reason = status.get("staleReason")
|
|
79
|
+
if isinstance(raw_status, str):
|
|
80
|
+
view["rawStatus"] = raw_status
|
|
81
|
+
if isinstance(effective_status, str):
|
|
82
|
+
view["effectiveStatus"] = effective_status
|
|
83
|
+
if isinstance(display_status, str):
|
|
84
|
+
view["status"] = display_status
|
|
85
|
+
if isinstance(stale_reason, str):
|
|
86
|
+
view["staleReason"] = stale_reason
|
|
87
|
+
return effective_status if isinstance(effective_status, str) else None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _write_identity_contract(
|
|
91
|
+
view: SnapshotView,
|
|
92
|
+
*,
|
|
93
|
+
run_id: str,
|
|
94
|
+
snapshot: JsonObject | None,
|
|
95
|
+
state: JsonObject | None,
|
|
96
|
+
manifest: JsonObject | None,
|
|
97
|
+
) -> str | None:
|
|
98
|
+
view["runId"] = run_id
|
|
99
|
+
alias = first_string(
|
|
100
|
+
_snapshot_value(snapshot, "alias"),
|
|
101
|
+
manifest.get("alias") if manifest else None,
|
|
102
|
+
state.get("alias") if state else None,
|
|
103
|
+
)
|
|
104
|
+
if alias is not None:
|
|
105
|
+
view["alias"] = alias
|
|
106
|
+
return alias
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _write_completion_report_contract(
|
|
110
|
+
view: SnapshotView,
|
|
111
|
+
snapshot: JsonObject | None,
|
|
112
|
+
) -> JsonObject | None:
|
|
113
|
+
completion_report = _snapshot_value(snapshot, "completionReport")
|
|
114
|
+
if isinstance(completion_report, dict):
|
|
115
|
+
view["completionReport"] = completion_report
|
|
116
|
+
return completion_report
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _source_workspace(
|
|
121
|
+
registry_root: Path,
|
|
122
|
+
snapshot: JsonObject | None,
|
|
123
|
+
state: JsonObject | None,
|
|
124
|
+
manifest: JsonObject | None,
|
|
125
|
+
) -> str:
|
|
126
|
+
return first_string(
|
|
127
|
+
manifest.get("cwd") if manifest else None,
|
|
128
|
+
state.get("cwd") if state else None,
|
|
129
|
+
_snapshot_value(snapshot, "cwd"),
|
|
130
|
+
str(registry_root.parent),
|
|
131
|
+
) or str(registry_root.parent)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def merge_snapshot_view(
|
|
135
|
+
registry_root: Path,
|
|
136
|
+
run_id: str,
|
|
137
|
+
snapshot: JsonObject | None,
|
|
138
|
+
*,
|
|
139
|
+
redact: bool,
|
|
140
|
+
) -> SnapshotView:
|
|
141
|
+
state = run_registry.load_run_state(registry_root, run_id)
|
|
142
|
+
manifest = run_registry.load_run_manifest(registry_root, run_id)
|
|
143
|
+
stdout_bytes, stderr_bytes = delegate_retention.effective_log_byte_sizes(registry_root, run_id)
|
|
144
|
+
view: SnapshotView = dict(snapshot or {})
|
|
145
|
+
if not view:
|
|
146
|
+
view = {
|
|
147
|
+
"schema": run_registry.SNAPSHOT_SCHEMA,
|
|
148
|
+
"ok": True,
|
|
149
|
+
}
|
|
150
|
+
view.setdefault("ok", True)
|
|
151
|
+
alias = _write_identity_contract(
|
|
152
|
+
view,
|
|
153
|
+
run_id=run_id,
|
|
154
|
+
snapshot=snapshot,
|
|
155
|
+
state=state,
|
|
156
|
+
manifest=manifest,
|
|
157
|
+
)
|
|
158
|
+
effective_status = _write_status_contract(view, state)
|
|
159
|
+
completion_report = _write_completion_report_contract(view, snapshot)
|
|
160
|
+
source_cwd = _source_workspace(registry_root, snapshot, state, manifest)
|
|
161
|
+
view["stdoutBytes"] = stdout_bytes
|
|
162
|
+
view["stderrBytes"] = stderr_bytes
|
|
163
|
+
if state:
|
|
164
|
+
for key in (
|
|
165
|
+
"lastActivityAt",
|
|
166
|
+
"current",
|
|
167
|
+
"exitCode",
|
|
168
|
+
"finishedAt",
|
|
169
|
+
"completionReportWritten",
|
|
170
|
+
"completionReportSource",
|
|
171
|
+
"resultQuality",
|
|
172
|
+
):
|
|
173
|
+
if key in state and key not in view:
|
|
174
|
+
view[key] = state[key]
|
|
175
|
+
# Surface pre-launch failure fields when status is "failed".
|
|
176
|
+
if state.get("status") == "failed":
|
|
177
|
+
for key in ("error", "message", "plannedBranch", "plannedExecutionCwd"):
|
|
178
|
+
if key in state and key not in view:
|
|
179
|
+
view[key] = state[key]
|
|
180
|
+
# Surface isolation metadata from state when present.
|
|
181
|
+
for key in run_metadata.SNAPSHOT_STATE_FALLBACK_KEYS:
|
|
182
|
+
if key in state and key not in view:
|
|
183
|
+
view[key] = state[key]
|
|
184
|
+
if manifest:
|
|
185
|
+
for key in ("alias", "harness", "cwd", "executionCwd", "mode", "model", "startedAt"):
|
|
186
|
+
if key in manifest and key not in view:
|
|
187
|
+
view[key] = manifest[key]
|
|
188
|
+
for key in run_metadata.SNAPSHOT_MANIFEST_FALLBACK_KEYS:
|
|
189
|
+
if key in manifest and key not in view:
|
|
190
|
+
view[key] = manifest[key]
|
|
191
|
+
warnings = list(view.get("warnings") or [])
|
|
192
|
+
for source in (state, manifest):
|
|
193
|
+
if not source:
|
|
194
|
+
continue
|
|
195
|
+
source_warnings = source.get("warnings")
|
|
196
|
+
if isinstance(source_warnings, list):
|
|
197
|
+
for warning in source_warnings:
|
|
198
|
+
if isinstance(warning, str) and warning not in warnings:
|
|
199
|
+
warnings.append(warning)
|
|
200
|
+
for warning in run_registry.large_log_warnings(stdout_bytes, stderr_bytes):
|
|
201
|
+
if warning not in warnings:
|
|
202
|
+
warnings.append(warning)
|
|
203
|
+
if delegate_retention.raw_logs_archived(registry_root, run_id):
|
|
204
|
+
archive_warning = delegate_retention.archived_log_warning(
|
|
205
|
+
alias if isinstance(alias, str) else None,
|
|
206
|
+
run_id,
|
|
207
|
+
cwd=source_cwd,
|
|
208
|
+
)
|
|
209
|
+
if archive_warning not in warnings:
|
|
210
|
+
warnings.append(archive_warning)
|
|
211
|
+
if warnings:
|
|
212
|
+
view["warnings"] = warnings
|
|
213
|
+
if isinstance(alias, str):
|
|
214
|
+
view["snapshotCommand"] = run_registry.snapshot_command(alias, cwd=source_cwd)
|
|
215
|
+
if effective_status == run_registry.STATUS_STALE:
|
|
216
|
+
view["nextActions"] = run_registry.stale_next_actions(alias, cwd=source_cwd)
|
|
217
|
+
if completion_report is not None:
|
|
218
|
+
completion_report["command"] = run_registry.run_output_command(
|
|
219
|
+
alias,
|
|
220
|
+
completion_report=True,
|
|
221
|
+
cwd=source_cwd,
|
|
222
|
+
)
|
|
223
|
+
if redact:
|
|
224
|
+
view = cast(SnapshotView, redact_value(view))
|
|
225
|
+
return view
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def snapshot_json_payload(view: SnapshotView) -> JsonObject:
|
|
229
|
+
return cast(dict[str, JsonValue], view)
|