deepagents-code 0.2.6__py3-none-any.whl → 0.2.8__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.
- deepagents_code/_build_info.py +1 -1
- deepagents_code/_env_vars.py +10 -0
- deepagents_code/_session_stats.py +19 -2
- deepagents_code/_version.py +1 -1
- deepagents_code/agent.py +11 -3
- deepagents_code/client/non_interactive.py +17 -34
- deepagents_code/completion.py +987 -0
- deepagents_code/config.py +23 -3
- deepagents_code/config_manifest.py +13 -0
- deepagents_code/cost_tracking.py +26 -1
- deepagents_code/editor.py +22 -0
- deepagents_code/git_evidence.py +60 -55
- deepagents_code/git_trace.py +198 -30
- deepagents_code/main.py +86 -6
- deepagents_code/tui/textual_adapter.py +9 -1
- deepagents_code/ui.py +44 -0
- {deepagents_code-0.2.6.dist-info → deepagents_code-0.2.8.dist-info}/METADATA +15 -15
- {deepagents_code-0.2.6.dist-info → deepagents_code-0.2.8.dist-info}/RECORD +22 -21
- {deepagents_code-0.2.6.data → deepagents_code-0.2.8.data}/data/deepagents_code/default_agent_prompt.md +0 -0
- {deepagents_code-0.2.6.dist-info → deepagents_code-0.2.8.dist-info}/WHEEL +0 -0
- {deepagents_code-0.2.6.dist-info → deepagents_code-0.2.8.dist-info}/entry_points.txt +0 -0
- {deepagents_code-0.2.6.dist-info → deepagents_code-0.2.8.dist-info}/licenses/LICENSE +0 -0
deepagents_code/_build_info.py
CHANGED
deepagents_code/_env_vars.py
CHANGED
|
@@ -318,6 +318,16 @@ Set only through the launching shell or global `~/.deepagents/.env`; a project
|
|
|
318
318
|
`.env` cannot set it.
|
|
319
319
|
"""
|
|
320
320
|
|
|
321
|
+
GIT_ATTRIBUTION = "DEEPAGENTS_CODE_GIT_ATTRIBUTION"
|
|
322
|
+
"""Toggle git attribution of LangSmith traces (defaults to on).
|
|
323
|
+
|
|
324
|
+
When enabled and tracing is active, dcode runs bounded, read-only `git`
|
|
325
|
+
inspections around tools that can change a checkout, so traces record the
|
|
326
|
+
repository and branch the agent actually worked on. Set to a falsy value (`0`,
|
|
327
|
+
`false`, `no`, `off`, or empty) to skip these inspections entirely, for example
|
|
328
|
+
in very large repositories. Also configurable as `[tracing].git_attribution`.
|
|
329
|
+
"""
|
|
330
|
+
|
|
321
331
|
GOAL_AUTO_ACCEPT_CRITERIA = "DEEPAGENTS_CODE_GOAL_AUTO_ACCEPT_CRITERIA"
|
|
322
332
|
"""Apply generated goal criteria automatically in Auto mode.
|
|
323
333
|
|
|
@@ -1237,6 +1237,23 @@ def is_model_usage_event(data: object) -> bool:
|
|
|
1237
1237
|
return isinstance(data, Mapping) and data.get("type") == MODEL_USAGE_EVENT_TYPE
|
|
1238
1238
|
|
|
1239
1239
|
|
|
1240
|
+
def is_summarization_started_event(data: object) -> bool:
|
|
1241
|
+
"""Report whether a custom-stream payload marks a summarization call starting.
|
|
1242
|
+
|
|
1243
|
+
Args:
|
|
1244
|
+
data: A `custom` stream payload.
|
|
1245
|
+
|
|
1246
|
+
Returns:
|
|
1247
|
+
`True` when the payload is a summarization start event.
|
|
1248
|
+
"""
|
|
1249
|
+
from deepagents_code.cost_tracking import SUMMARIZATION_STARTED_EVENT_TYPE
|
|
1250
|
+
|
|
1251
|
+
return (
|
|
1252
|
+
isinstance(data, Mapping)
|
|
1253
|
+
and data.get("type") == SUMMARIZATION_STARTED_EVENT_TYPE
|
|
1254
|
+
)
|
|
1255
|
+
|
|
1256
|
+
|
|
1240
1257
|
def record_model_usage_event(
|
|
1241
1258
|
stats: SessionStats,
|
|
1242
1259
|
data: object,
|
|
@@ -1288,7 +1305,7 @@ def record_model_usage_event(
|
|
|
1288
1305
|
or not isinstance(thread_id, str)
|
|
1289
1306
|
or not thread_id
|
|
1290
1307
|
or not isinstance(scope, str)
|
|
1291
|
-
or not scope
|
|
1308
|
+
or (not scope and data.get("lc_source") != "summarization")
|
|
1292
1309
|
or not isinstance(usage, Mapping)
|
|
1293
1310
|
or not usage
|
|
1294
1311
|
or not isinstance(model_name, str)
|
|
@@ -1319,7 +1336,7 @@ def record_model_usage_event(
|
|
|
1319
1336
|
message,
|
|
1320
1337
|
fallback_model=fallback_model,
|
|
1321
1338
|
fallback_provider=fallback_provider,
|
|
1322
|
-
kind="subagent",
|
|
1339
|
+
kind="subagent" if scope else "offload",
|
|
1323
1340
|
recorded_requests=recorded_requests,
|
|
1324
1341
|
attempt_scope=attempt_scope,
|
|
1325
1342
|
invocation_id=invocation_id or None,
|
deepagents_code/_version.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Keep the `x-release-please-version` annotation — release-please uses it to
|
|
4
4
|
# bump `__version__` in sync with `pyproject.toml` on every release PR.
|
|
5
|
-
__version__ = "0.2.
|
|
5
|
+
__version__ = "0.2.8" # x-release-please-version
|
|
6
6
|
|
|
7
7
|
DOCS_URL = "https://docs.langchain.com/oss/python/deepagents/code"
|
|
8
8
|
"""URL for `deepagents-code` documentation."""
|
deepagents_code/agent.py
CHANGED
|
@@ -115,6 +115,7 @@ from deepagents_code.config import (
|
|
|
115
115
|
get_default_coding_instructions,
|
|
116
116
|
get_glyphs,
|
|
117
117
|
get_langsmith_project_name,
|
|
118
|
+
is_git_attribution_enabled,
|
|
118
119
|
restore_user_langsmith_env,
|
|
119
120
|
runtime_state,
|
|
120
121
|
)
|
|
@@ -2832,7 +2833,11 @@ def create_cli_agent(
|
|
|
2832
2833
|
if effective_cwd is not None
|
|
2833
2834
|
else ""
|
|
2834
2835
|
)
|
|
2835
|
-
git_trace =
|
|
2836
|
+
git_trace: list[AgentMiddleware[Any, Any]] = (
|
|
2837
|
+
[GitTraceMiddleware(lambda: backend, trace_cwd)]
|
|
2838
|
+
if is_git_attribution_enabled()
|
|
2839
|
+
else []
|
|
2840
|
+
)
|
|
2836
2841
|
|
|
2837
2842
|
# Setup agent directory for persistent memory (if enabled)
|
|
2838
2843
|
if enable_memory or enable_skills:
|
|
@@ -2893,7 +2898,7 @@ def create_cli_agent(
|
|
|
2893
2898
|
) -> list[AgentMiddleware[Any, Any]]:
|
|
2894
2899
|
from deepagents_code.cost_tracking import CostTrackingMiddleware
|
|
2895
2900
|
|
|
2896
|
-
middleware: list[AgentMiddleware[Any, Any]] = [git_trace]
|
|
2901
|
+
middleware: list[AgentMiddleware[Any, Any]] = [*git_trace]
|
|
2897
2902
|
if resolved_interrupt_on is not None:
|
|
2898
2903
|
middleware.append(AsyncApprovalHITLMiddleware(resolved_interrupt_on))
|
|
2899
2904
|
if not has_explicit_model:
|
|
@@ -3074,7 +3079,7 @@ def create_cli_agent(
|
|
|
3074
3079
|
|
|
3075
3080
|
# Build middleware stack based on enabled features
|
|
3076
3081
|
agent_middleware: list[AgentMiddleware[Any, Any]] = [
|
|
3077
|
-
git_trace,
|
|
3082
|
+
*git_trace,
|
|
3078
3083
|
ConfigurableModelMiddleware(
|
|
3079
3084
|
cli_max_retries=cli_max_retries,
|
|
3080
3085
|
environ=environment,
|
|
@@ -3196,6 +3201,9 @@ def create_cli_agent(
|
|
|
3196
3201
|
# agent-only credentials in the workspace environment.
|
|
3197
3202
|
shell_env = dict(environment)
|
|
3198
3203
|
shell_env["GIT_TERMINAL_PROMPT"] = "0"
|
|
3204
|
+
# Lets CLIs the agent runs tell the call came from dcode, the way
|
|
3205
|
+
# Claude Code sets `CLAUDECODE` and Cursor sets `CURSOR_AGENT`.
|
|
3206
|
+
shell_env["DEEPAGENTS_CODE"] = "1"
|
|
3199
3207
|
restore_user_langsmith_env(shell_env, start_path=effective_cwd)
|
|
3200
3208
|
user_tracing_project = shell_env.get("LANGSMITH_PROJECT")
|
|
3201
3209
|
# Re-apply a launch-time PYTHONPATH that was stripped from the server
|
|
@@ -48,6 +48,8 @@ from deepagents_code._session_stats import (
|
|
|
48
48
|
UsageLedgerKey,
|
|
49
49
|
classify_usage_kind,
|
|
50
50
|
finalize_recorded_requests,
|
|
51
|
+
is_model_usage_event,
|
|
52
|
+
is_summarization_started_event,
|
|
51
53
|
print_usage_table,
|
|
52
54
|
record_message_usage,
|
|
53
55
|
record_model_usage_event,
|
|
@@ -199,36 +201,6 @@ def _write_newline() -> None:
|
|
|
199
201
|
sys.stdout.flush()
|
|
200
202
|
|
|
201
203
|
|
|
202
|
-
def _make_stdio_encoding_safe() -> None:
|
|
203
|
-
"""Prevent `UnicodeEncodeError` from killing a non-interactive run.
|
|
204
|
-
|
|
205
|
-
Legacy Windows consoles default to a locale code page (e.g. cp1252) that
|
|
206
|
-
cannot encode decorative Unicode glyphs; the first `console.print()` containing one
|
|
207
|
-
then crashes the whole run. Reconfiguring the streams with
|
|
208
|
-
`errors="replace"` degrades unencodable characters to "?" instead. The
|
|
209
|
-
stream encoding itself is left untouched.
|
|
210
|
-
"""
|
|
211
|
-
for stream in (sys.stdout, sys.stderr):
|
|
212
|
-
# Streams replaced by non-reconfigurable objects (e.g. a plain
|
|
213
|
-
# StringIO or a captured buffer) are left as-is.
|
|
214
|
-
reconfigure = getattr(stream, "reconfigure", None)
|
|
215
|
-
if reconfigure is None:
|
|
216
|
-
continue
|
|
217
|
-
try:
|
|
218
|
-
reconfigure(errors="replace")
|
|
219
|
-
except ValueError, OSError, TypeError:
|
|
220
|
-
# Closed, detached, or otherwise non-reconfigurable stream (a
|
|
221
|
-
# duck-typed `reconfigure` with a different signature raises
|
|
222
|
-
# `TypeError`) — leave it as-is. This is a best-effort hardening
|
|
223
|
-
# step; it must never itself crash the run.
|
|
224
|
-
logger.debug(
|
|
225
|
-
"Could not reconfigure %s error handler",
|
|
226
|
-
getattr(stream, "name", stream),
|
|
227
|
-
exc_info=True,
|
|
228
|
-
)
|
|
229
|
-
continue
|
|
230
|
-
|
|
231
|
-
|
|
232
204
|
class _ConsoleSpinner:
|
|
233
205
|
"""Animated spinner for non-interactive verbose output.
|
|
234
206
|
|
|
@@ -1669,7 +1641,16 @@ def _process_stream_chunk(
|
|
|
1669
1641
|
if stream_mode == "updates" and isinstance(data, dict) and "__interrupt__" in data:
|
|
1670
1642
|
_process_interrupts(cast("dict[str, list[Interrupt]]", data), state, console)
|
|
1671
1643
|
elif stream_mode == "custom" and isinstance(data, dict):
|
|
1672
|
-
if data
|
|
1644
|
+
if is_model_usage_event(data):
|
|
1645
|
+
record_model_usage_event(
|
|
1646
|
+
state.stats,
|
|
1647
|
+
data,
|
|
1648
|
+
active_thread_id=state.thread_id,
|
|
1649
|
+
fallback_model=runtime_state.model_name or "",
|
|
1650
|
+
fallback_provider=runtime_state.model_provider or "",
|
|
1651
|
+
recorded_requests=state.recorded_usage_requests,
|
|
1652
|
+
)
|
|
1653
|
+
elif data.get("type") == "model_retry":
|
|
1673
1654
|
correlation = model_retry_from_event(data)
|
|
1674
1655
|
if correlation is not None:
|
|
1675
1656
|
_process_retry_lifecycle(
|
|
@@ -1965,7 +1946,9 @@ async def _stream_agent(
|
|
|
1965
1946
|
):
|
|
1966
1947
|
summarization = _summarization_stream_status(chunk)
|
|
1967
1948
|
compaction_id = _compaction_result_id(chunk)
|
|
1968
|
-
if summarization
|
|
1949
|
+
if summarization:
|
|
1950
|
+
state.summarization_observed = True
|
|
1951
|
+
elif summarization is False and state.summarization_observed:
|
|
1969
1952
|
if compaction_id is not None:
|
|
1970
1953
|
state.completed_compaction_ids.add(compaction_id)
|
|
1971
1954
|
await _after_headless_compact(state)
|
|
@@ -1996,6 +1979,8 @@ def _summarization_stream_status(chunk: object) -> bool | None:
|
|
|
1996
1979
|
namespace, stream_mode, data = chunk
|
|
1997
1980
|
if namespace:
|
|
1998
1981
|
return None
|
|
1982
|
+
if stream_mode == "custom":
|
|
1983
|
+
return True if is_summarization_started_event(data) else None
|
|
1999
1984
|
if (
|
|
2000
1985
|
stream_mode != "messages"
|
|
2001
1986
|
or not isinstance(data, tuple)
|
|
@@ -2928,8 +2913,6 @@ async def run_non_interactive(
|
|
|
2928
2913
|
when the `--max-turns` budget was exceeded (matching GNU `timeout`),
|
|
2929
2914
|
130 for keyboard interrupt.
|
|
2930
2915
|
"""
|
|
2931
|
-
_make_stdio_encoding_safe()
|
|
2932
|
-
|
|
2933
2916
|
# stderr=True routes all console.print() to stderr; agent response text
|
|
2934
2917
|
# uses _write_text() -> sys.stdout directly.
|
|
2935
2918
|
console = Console(stderr=True) if quiet else Console()
|