teddy-cli 0.2.3.dev1530__py3-none-any.whl → 0.2.3.dev1531__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.
- {teddy_cli-0.2.3.dev1530.dist-info → teddy_cli-0.2.3.dev1531.dist-info}/METADATA +1 -1
- {teddy_cli-0.2.3.dev1530.dist-info → teddy_cli-0.2.3.dev1531.dist-info}/RECORD +14 -14
- teddy_executor/adapters/inbound/session_cli_handlers.py +15 -1
- teddy_executor/adapters/inbound/textual_plan_reviewer_helpers.py +21 -10
- teddy_executor/adapters/inbound/textual_plan_reviewer_logic.py +2 -1
- teddy_executor/core/domain/models/project_context.py +2 -0
- teddy_executor/core/ports/inbound/get_context_use_case.py +4 -1
- teddy_executor/core/services/context_service.py +14 -8
- teddy_executor/core/services/planning_service.py +3 -1
- teddy_executor/core/services/session_orchestrator.py +1 -0
- teddy_executor/core/utils/markdown.py +40 -7
- {teddy_cli-0.2.3.dev1530.dist-info → teddy_cli-0.2.3.dev1531.dist-info}/WHEEL +0 -0
- {teddy_cli-0.2.3.dev1530.dist-info → teddy_cli-0.2.3.dev1531.dist-info}/entry_points.txt +0 -0
- {teddy_cli-0.2.3.dev1530.dist-info → teddy_cli-0.2.3.dev1531.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,13 +6,13 @@ teddy_executor/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
|
6
6
|
teddy_executor/adapters/inbound/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
teddy_executor/adapters/inbound/cli_formatter.py,sha256=9bWL2S-3vZFBJZPd4RG2xTBYWu1Tim6U0AMGRjcUHB8,3548
|
|
8
8
|
teddy_executor/adapters/inbound/cli_helpers.py,sha256=yXGJYEPPMCmH2AKBwEhW-CkWmHGf7OgDTOE-qMLR4d0,9377
|
|
9
|
-
teddy_executor/adapters/inbound/session_cli_handlers.py,sha256=
|
|
9
|
+
teddy_executor/adapters/inbound/session_cli_handlers.py,sha256=tx1zYxR5dafRCfJu2ISkDYUiPntV51jjE3bA448AWeA,62362
|
|
10
10
|
teddy_executor/adapters/inbound/textual_plan_reviewer.py,sha256=lJHoqaJShuvTVz7SvEdikHN_rMCXPbgolUVlYVkoc4s,3678
|
|
11
11
|
teddy_executor/adapters/inbound/textual_plan_reviewer_app.py,sha256=ipOw8QLoOfoGcZdo3R4-zaMBQ2RuHilk2dXsMGoYrBc,15209
|
|
12
12
|
teddy_executor/adapters/inbound/textual_plan_reviewer_editor.py,sha256=LbYlIXSoEc3PQ8o28O4lzybMBig9r0QKYFNKg90iso0,22235
|
|
13
13
|
teddy_executor/adapters/inbound/textual_plan_reviewer_execution.py,sha256=QjkAB4aP7URG1lAOShHrojtAbLWEXZINIHfIrAM8lIA,7322
|
|
14
|
-
teddy_executor/adapters/inbound/textual_plan_reviewer_helpers.py,sha256=
|
|
15
|
-
teddy_executor/adapters/inbound/textual_plan_reviewer_logic.py,sha256=
|
|
14
|
+
teddy_executor/adapters/inbound/textual_plan_reviewer_helpers.py,sha256=IoCfxDIqn1iVw-ijefFe8tjztlzU0KBo8GqVUMnsTLo,12068
|
|
15
|
+
teddy_executor/adapters/inbound/textual_plan_reviewer_logic.py,sha256=En3jzsr0M_LwvEN2q0ZL8QhI8AmgRhI0QUnAhJJygQk,11460
|
|
16
16
|
teddy_executor/adapters/inbound/textual_plan_reviewer_previews.py,sha256=lNg0drAVGkQ40fmlK-IcDKh4tLCKzsSsXFq2gdjPBW0,12017
|
|
17
17
|
teddy_executor/adapters/inbound/textual_plan_reviewer_widgets.py,sha256=_-pfFY_71m0s3tDKzqH_l28fF563V0h3cZXYPKvS2kI,7356
|
|
18
18
|
teddy_executor/adapters/outbound/__init__.py,sha256=YN-oxkFQlMVrj3YdAJoLKXA_uo91cSU4llc3UHJ1Ckg,157
|
|
@@ -47,7 +47,7 @@ teddy_executor/core/domain/models/execution_report.py,sha256=1jUI1YHhx0FruuMh6gY
|
|
|
47
47
|
teddy_executor/core/domain/models/orchestrator_ports.py,sha256=aBnyC2KYBpBz1khLiQ9n9fPOrqt07xYyjNXDugh0r80,1165
|
|
48
48
|
teddy_executor/core/domain/models/plan.py,sha256=J2fgkY2OOOJ2HXHmfrey0O8rDPCezw-047us-3V3qGc,2284
|
|
49
49
|
teddy_executor/core/domain/models/planning_ports.py,sha256=vZ0e4LRJHSCEMRApX-M1PmUvuSlhLQ1NCPfzBSpn4ko,2199
|
|
50
|
-
teddy_executor/core/domain/models/project_context.py,sha256=
|
|
50
|
+
teddy_executor/core/domain/models/project_context.py,sha256=gZc2SaKDUR7KNC47PZVLCj57RPfJxIPv9LFGkDRjOYU,1827
|
|
51
51
|
teddy_executor/core/domain/models/report_assembly_data.py,sha256=HuLqpha3cZ_V7BZ8pdsdIxnxVvCJ8_-o30PQVdkydrE,432
|
|
52
52
|
teddy_executor/core/domain/models/session.py,sha256=hiAhnvtAD1VawCWtbkIu6wvRt2_th3PcCClLJ6CwcAo,385
|
|
53
53
|
teddy_executor/core/domain/models/shell_output.py,sha256=yUmK9_tobgWAVr8_J47FGH7x8GpkwYfaH1CLFp6l-ls,486
|
|
@@ -55,7 +55,7 @@ teddy_executor/core/domain/models/web_search_results.py,sha256=ZugVr76XB2QdS-vum
|
|
|
55
55
|
teddy_executor/core/ports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
56
56
|
teddy_executor/core/ports/inbound/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
57
57
|
teddy_executor/core/ports/inbound/edit_simulator.py,sha256=Pu4tBJxK4ensZO1gH_YE_NuVMG99qzy6v5Q4pN_VT5s,1087
|
|
58
|
-
teddy_executor/core/ports/inbound/get_context_use_case.py,sha256=
|
|
58
|
+
teddy_executor/core/ports/inbound/get_context_use_case.py,sha256=JYYvG6f0UYh0CTcJ39oTUvAR9UfYifiu1lSeWHR9tlA,1324
|
|
59
59
|
teddy_executor/core/ports/inbound/init.py,sha256=3iJH2I2ljpZq2-f-XditbmRySUgFuBFUF_j7UkY6p_E,2496
|
|
60
60
|
teddy_executor/core/ports/inbound/plan_parser.py,sha256=BaH1XQM23ys6l4YMcb2VTXs7IjW2TgklUqQ-8dthSYQ,1603
|
|
61
61
|
teddy_executor/core/ports/inbound/plan_reviewer.py,sha256=iHJfl4P7P6kOr2QERBAuXRaQwtgE7eiqOdQDpeMotmY,1247
|
|
@@ -89,7 +89,7 @@ teddy_executor/core/services/action_executor.py,sha256=kjlQM3Hx4Cmq95HKQyeYM3M0Y
|
|
|
89
89
|
teddy_executor/core/services/action_factory.py,sha256=-FV_V4sy7CcuuPU8Xb3mqvQp_-BaoVodorVcVjUjzVo,9305
|
|
90
90
|
teddy_executor/core/services/action_parser_complex.py,sha256=7vDUsHFvclElkdngCypZdzka1fZy0O4f__q4-MsulPI,6848
|
|
91
91
|
teddy_executor/core/services/action_parser_strategies.py,sha256=o_aBiMRiHsepmsNveYxmr1_Ll73KVhMSBaUA7nBE604,2705
|
|
92
|
-
teddy_executor/core/services/context_service.py,sha256=
|
|
92
|
+
teddy_executor/core/services/context_service.py,sha256=Buri7h1GXs1dXhQaIZEtB-JxrN3-SbtXgoRt4YXFdAg,21585
|
|
93
93
|
teddy_executor/core/services/edit_simulator.py,sha256=5Z_SCBfGHTaGi-JVIgyIDeTGr-5Pulm6A5Ifqn7SSmU,5512
|
|
94
94
|
teddy_executor/core/services/execution_orchestrator.py,sha256=jnfUR52_JKsDep0BVTTAhokiEQIOUx1WSjl9_d4y-qU,15047
|
|
95
95
|
teddy_executor/core/services/execution_report_assembler.py,sha256=227YExXeAtf0GQLnc4IDLKqZi1QsxOYKqvMcWSs2NVo,2396
|
|
@@ -100,11 +100,11 @@ teddy_executor/core/services/parser_infrastructure.py,sha256=joDtWf3rXsEaDSasTff
|
|
|
100
100
|
teddy_executor/core/services/parser_metadata.py,sha256=HEbzQpISeEQqD8xGiXQhaOtV8FdJz5pOnkb9hk1cVII,8493
|
|
101
101
|
teddy_executor/core/services/parser_reporting.py,sha256=shD3UAiFTooQH_AvLk5GR3rZmqoXmIZXuxymqxwggwQ,9988
|
|
102
102
|
teddy_executor/core/services/plan_validator.py,sha256=fHCuMo3ETkJgP5Nbcy0JuFGucUyk5Pgo-GoQB7XPiT0,2906
|
|
103
|
-
teddy_executor/core/services/planning_service.py,sha256=
|
|
103
|
+
teddy_executor/core/services/planning_service.py,sha256=1Ah4roSn8nSVdNhxJlrNVeUoxkYBjXsBEjMfy9cAqFA,11945
|
|
104
104
|
teddy_executor/core/services/prompt_manager.py,sha256=NJpgeqxwPaYfrmC5ZrGfmIs-HC4bHoTwu3uaKcfFSxA,10613
|
|
105
105
|
teddy_executor/core/services/session_lifecycle_manager.py,sha256=AzbjYzlc968bEGVH8257s-dYYW5yTqHYS1y0PJ4XEPo,36213
|
|
106
106
|
teddy_executor/core/services/session_loop_guard.py,sha256=_z45KXaF7VQJTXQT18M6QR5Lq6VCzKqrbhugXg7UWVk,4480
|
|
107
|
-
teddy_executor/core/services/session_orchestrator.py,sha256=
|
|
107
|
+
teddy_executor/core/services/session_orchestrator.py,sha256=_NIXCgd8sRjbBwgcxLN-99SqDkoubGWVPxN_w_sjOJk,27683
|
|
108
108
|
teddy_executor/core/services/session_planner.py,sha256=hrb3EBXzNAfV1qyCKR159oUMRB29Vv02ZmyPwLhcYpc,1695
|
|
109
109
|
teddy_executor/core/services/session_pruning_service.py,sha256=ZufCk452G3V1iYUbFpGNq6mZZHG6Zwk_6QvXYqx1tgk,16100
|
|
110
110
|
teddy_executor/core/services/session_replanner.py,sha256=-6r0wGSz9TMOPZi9rKe2OWMhufQso45yrA93z4FA6Fc,2629
|
|
@@ -126,7 +126,7 @@ teddy_executor/core/utils/editor_names.py,sha256=Z1OSyNYLexgGmt7tcxyjb43_DsY14cC
|
|
|
126
126
|
teddy_executor/core/utils/interrupt_guard.py,sha256=T-HnfIaQl-X_xVIORu76K-z5BpvOcfwqL2yfG0X9eq4,6072
|
|
127
127
|
teddy_executor/core/utils/interruptible_call.py,sha256=9Q_9a3cD9krbdoimx5GGIIUjplK1of2JaqxEu5APOnE,1749
|
|
128
128
|
teddy_executor/core/utils/io.py,sha256=rK5GyhPXKqkl6R-HNAMezJwNeMsC3Ae18g32rMKcMpk,4058
|
|
129
|
-
teddy_executor/core/utils/markdown.py,sha256=
|
|
129
|
+
teddy_executor/core/utils/markdown.py,sha256=aA92YkiXc5FnBXQEGjt6Lv0Oyg2j-FUFjtjBKN20dx4,10433
|
|
130
130
|
teddy_executor/core/utils/message_renderer.py,sha256=nn1be_BctJK2aw0GPIQsABi-HJE5_Lfz7xDyKzHlT_w,2598
|
|
131
131
|
teddy_executor/core/utils/paths.py,sha256=iDRNcqtWEUvJVZOFLPEcoPdwtRCmqF5HHhV050GPsas,3421
|
|
132
132
|
teddy_executor/core/utils/serialization.py,sha256=V_1jyPeRm670HlbIKhrW8LP1s6O4UCc8xo0kmky9EDs,1237
|
|
@@ -159,8 +159,8 @@ teddy_executor/resources/templates/milestone.md,sha256=PwHedgzqRQnKQq4M4GILmmv7Y
|
|
|
159
159
|
teddy_executor/resources/templates/pre-commit.md,sha256=NqllfAw8Z0yvt51QJ6OBW18dccrJniLGibSylkatvRM,7684
|
|
160
160
|
teddy_executor/resources/templates/specification-document.md,sha256=skYPZ7E0m2n2STEWOKCHeiuqNtsshYzI49rmsNSKAuA,671
|
|
161
161
|
teddy_executor/resources/templates/vertical-slice.md,sha256=Cn8Y_rb6BZvy9bKBDNXhGfoSgMpsZbIBfyFQgrdx8Jg,5563
|
|
162
|
-
teddy_cli-0.2.3.
|
|
163
|
-
teddy_cli-0.2.3.
|
|
164
|
-
teddy_cli-0.2.3.
|
|
165
|
-
teddy_cli-0.2.3.
|
|
166
|
-
teddy_cli-0.2.3.
|
|
162
|
+
teddy_cli-0.2.3.dev1531.dist-info/METADATA,sha256=vxZ8EqBJN9gfFO9ErNKhYUrux_tYHeSwV42_M76tUx4,30646
|
|
163
|
+
teddy_cli-0.2.3.dev1531.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
164
|
+
teddy_cli-0.2.3.dev1531.dist-info/entry_points.txt,sha256=3KaK1-CWsscLZeHduI6Jgime9aw_gfmdQZ7AUkA0QDg,54
|
|
165
|
+
teddy_cli-0.2.3.dev1531.dist-info/licenses/LICENSE,sha256=HBL2C3ynq_mk-EYtJI7aXEc6gXnXgKJ-K6KZ13N0Ojs,35270
|
|
166
|
+
teddy_cli-0.2.3.dev1531.dist-info/RECORD,,
|
|
@@ -1401,6 +1401,18 @@ def detect_session_context() -> Optional[Dict[str, Sequence[str]]]:
|
|
|
1401
1401
|
return None
|
|
1402
1402
|
|
|
1403
1403
|
|
|
1404
|
+
def detect_session_root() -> Optional[str]:
|
|
1405
|
+
"""Resolves the current session's root, or None outside a session.
|
|
1406
|
+
|
|
1407
|
+
Derives from `detect_session_context` so the three-file session gate lives
|
|
1408
|
+
in one place. The scope map that function returns must not be reused as a
|
|
1409
|
+
path source, because `--only` and `-c` override it.
|
|
1410
|
+
"""
|
|
1411
|
+
if detect_session_context() is None:
|
|
1412
|
+
return None
|
|
1413
|
+
return str(Path.cwd().parent)
|
|
1414
|
+
|
|
1415
|
+
|
|
1404
1416
|
def _default_context_paths(container: Container) -> list[str]:
|
|
1405
1417
|
"""Resolves the default `.teddy/*.context` entries outside a session."""
|
|
1406
1418
|
file_system_manager = container.resolve(IFileSystemManager)
|
|
@@ -1436,7 +1448,9 @@ def handle_context_gathering(
|
|
|
1436
1448
|
|
|
1437
1449
|
# Performance: Formatting context for Markdown doesn't use tokens, so we skip them.
|
|
1438
1450
|
context_result = context_service.get_context(
|
|
1439
|
-
context_files=context_files,
|
|
1451
|
+
context_files=context_files,
|
|
1452
|
+
include_tokens=False,
|
|
1453
|
+
session_root=detect_session_root(),
|
|
1440
1454
|
)
|
|
1441
1455
|
formatted_context = format_project_context(context_result)
|
|
1442
1456
|
echo_and_copy(formatted_context, no_copy=no_copy)
|
|
@@ -77,18 +77,22 @@ def populate_context_detail(app: "ReviewerApp", pane: Any, data: Any) -> None:
|
|
|
77
77
|
f"{(app.project_context.system_prompt_tokens + system_info_tokens) / 1000.0:.1f}k",
|
|
78
78
|
)
|
|
79
79
|
)
|
|
80
|
+
session_root = app.project_context.session_root
|
|
80
81
|
session_tokens = sum(
|
|
81
82
|
i.token_count
|
|
82
83
|
for i in selected_items
|
|
83
|
-
if i.scope == "Session"
|
|
84
|
+
if i.scope == "Session"
|
|
85
|
+
and not is_session_history_path(i.path, session_root)
|
|
84
86
|
)
|
|
85
87
|
turn_tokens = sum(
|
|
86
88
|
i.token_count
|
|
87
89
|
for i in selected_items
|
|
88
|
-
if i.scope == "Turn" and not is_session_history_path(i.path)
|
|
90
|
+
if i.scope == "Turn" and not is_session_history_path(i.path, session_root)
|
|
89
91
|
)
|
|
90
92
|
history_tokens = sum(
|
|
91
|
-
i.token_count
|
|
93
|
+
i.token_count
|
|
94
|
+
for i in selected_items
|
|
95
|
+
if is_session_history_path(i.path, session_root)
|
|
92
96
|
)
|
|
93
97
|
|
|
94
98
|
pane.append(DetailItem("• Session", f"{session_tokens / 1000.0:.1f}k"))
|
|
@@ -99,7 +103,9 @@ def populate_context_detail(app: "ReviewerApp", pane: Any, data: Any) -> None:
|
|
|
99
103
|
# Editor helpers moved to textual_plan_reviewer_editor.py
|
|
100
104
|
|
|
101
105
|
|
|
102
|
-
def format_context_item_label(
|
|
106
|
+
def format_context_item_label(
|
|
107
|
+
item: "ContextItem", session_root: str | None = None
|
|
108
|
+
) -> str:
|
|
103
109
|
"""Format a context item label according to UI standards."""
|
|
104
110
|
status_colors = {
|
|
105
111
|
"M": "yellow",
|
|
@@ -119,7 +125,7 @@ def format_context_item_label(item: "ContextItem") -> str:
|
|
|
119
125
|
|
|
120
126
|
from teddy_executor.core.utils.markdown import get_session_history_display_name
|
|
121
127
|
|
|
122
|
-
disp_name = get_session_history_display_name(item.path)
|
|
128
|
+
disp_name = get_session_history_display_name(item.path, session_root)
|
|
123
129
|
display_path = disp_name if disp_name else item.path
|
|
124
130
|
|
|
125
131
|
if not item.selected:
|
|
@@ -139,11 +145,12 @@ def build_context_section(app: "ReviewerApp", tree: Any) -> Any:
|
|
|
139
145
|
HISTORY_LABEL,
|
|
140
146
|
)
|
|
141
147
|
from teddy_executor.core.utils.markdown import (
|
|
142
|
-
|
|
148
|
+
is_own_session_path,
|
|
143
149
|
is_session_history_path,
|
|
144
150
|
get_session_history_sort_key,
|
|
145
151
|
)
|
|
146
152
|
|
|
153
|
+
session_root = app.project_context.session_root
|
|
147
154
|
con_root = tree.root.add("[bold]Context[/]", data=CONTEXT_ROOT, expand=False)
|
|
148
155
|
con_root.add_leaf("[#888888 italic]System:[/]", data=SYSTEM_LABEL)
|
|
149
156
|
token_str = f" [#888888]{app.project_context.system_prompt_tokens / 1000.0:.1f}k[/]"
|
|
@@ -161,21 +168,25 @@ def build_context_section(app: "ReviewerApp", tree: Any) -> Any:
|
|
|
161
168
|
con_root.add_leaf(f"[#888888 italic]{scope}:[/]", data=label)
|
|
162
169
|
count = 0
|
|
163
170
|
for item in app.project_context.items:
|
|
164
|
-
if item.scope == scope and not
|
|
165
|
-
con_root.add_leaf(
|
|
171
|
+
if item.scope == scope and not is_own_session_path(item.path, session_root):
|
|
172
|
+
con_root.add_leaf(
|
|
173
|
+
format_context_item_label(item, session_root), data=item
|
|
174
|
+
)
|
|
166
175
|
count += 1
|
|
167
176
|
if count == 0:
|
|
168
177
|
con_root.add_leaf(" [#888888](None)[/]", data=label)
|
|
169
178
|
|
|
170
179
|
# Chronological history turns
|
|
171
180
|
history_items = [
|
|
172
|
-
item
|
|
181
|
+
item
|
|
182
|
+
for item in app.project_context.items
|
|
183
|
+
if is_session_history_path(item.path, session_root)
|
|
173
184
|
]
|
|
174
185
|
if history_items:
|
|
175
186
|
con_root.add_leaf("[#888888 italic]History:[/]", data=HISTORY_LABEL)
|
|
176
187
|
history_items.sort(key=lambda x: get_session_history_sort_key(x.path))
|
|
177
188
|
for item in history_items:
|
|
178
|
-
con_root.add_leaf(format_context_item_label(item), data=item)
|
|
189
|
+
con_root.add_leaf(format_context_item_label(item, session_root), data=item)
|
|
179
190
|
|
|
180
191
|
return con_root
|
|
181
192
|
|
|
@@ -184,7 +184,8 @@ def refresh_node_logic(app: ReviewerApp, node: Any) -> None:
|
|
|
184
184
|
if isinstance(node.data, ActionData):
|
|
185
185
|
node.label = format_node_label(node.data)
|
|
186
186
|
elif isinstance(node.data, ContextItem):
|
|
187
|
-
|
|
187
|
+
session_root = app.project_context.session_root if app.project_context else None
|
|
188
|
+
node.label = format_context_item_label(node.data, session_root)
|
|
188
189
|
|
|
189
190
|
|
|
190
191
|
def on_mount_logic(app: Any) -> None:
|
|
@@ -43,6 +43,7 @@ class ProjectContext:
|
|
|
43
43
|
agent_name: Name of the active agent.
|
|
44
44
|
system_prompt_tokens: Token count of the system prompt.
|
|
45
45
|
total_window: Total context window for the model.
|
|
46
|
+
session_root: Optional root of the session the context was assembled for.
|
|
46
47
|
"""
|
|
47
48
|
|
|
48
49
|
header: str
|
|
@@ -54,3 +55,4 @@ class ProjectContext:
|
|
|
54
55
|
system_prompt_tokens: int = 0
|
|
55
56
|
content_tokens: int = 0
|
|
56
57
|
total_window: int = 0
|
|
58
|
+
session_root: Optional[str] = None
|
|
@@ -8,7 +8,7 @@ class IGetContextUseCase(Protocol):
|
|
|
8
8
|
This defines the contract for the primary entry point for gathering project context.
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
-
def get_context(
|
|
11
|
+
def get_context( # noqa: PLR0913 - inbound-port seam; additive keyword
|
|
12
12
|
self,
|
|
13
13
|
context_files: Optional[Dict[str, Sequence[str]]] = None,
|
|
14
14
|
include_tokens: bool = True,
|
|
@@ -17,6 +17,7 @@ class IGetContextUseCase(Protocol):
|
|
|
17
17
|
cache_dir: Optional[str] = None,
|
|
18
18
|
current_turn: Optional[str] = None,
|
|
19
19
|
system_prompt_tokens: int = 0,
|
|
20
|
+
session_root: Optional[str] = None,
|
|
20
21
|
) -> ProjectContext:
|
|
21
22
|
"""
|
|
22
23
|
Gathers all project context information.
|
|
@@ -25,6 +26,8 @@ class IGetContextUseCase(Protocol):
|
|
|
25
26
|
context_files: Optional mapping of scope names to .context files.
|
|
26
27
|
current_turn: Optional 2-digit turn number to include in the header.
|
|
27
28
|
system_prompt_tokens: Token count of the system prompt (pre-computed).
|
|
29
|
+
session_root: Optional root of the rendering session, used to gate
|
|
30
|
+
session-history classification.
|
|
28
31
|
|
|
29
32
|
Returns:
|
|
30
33
|
ProjectContext: A data object containing the aggregated context.
|
|
@@ -6,7 +6,8 @@ from teddy_executor.core.domain.models import ProjectContext, ContextItem
|
|
|
6
6
|
from teddy_executor.core.utils.markdown import (
|
|
7
7
|
embed_in_fence,
|
|
8
8
|
get_language_from_path,
|
|
9
|
-
|
|
9
|
+
is_own_session_path,
|
|
10
|
+
is_session_history_path,
|
|
10
11
|
get_session_history_display_name,
|
|
11
12
|
get_session_history_sort_key,
|
|
12
13
|
)
|
|
@@ -53,6 +54,7 @@ class ContextService(IGetContextUseCase):
|
|
|
53
54
|
cache_dir: Optional[str] = None,
|
|
54
55
|
current_turn: Optional[str] = None,
|
|
55
56
|
system_prompt_tokens: int = 0,
|
|
57
|
+
session_root: Optional[str] = None,
|
|
56
58
|
) -> ProjectContext:
|
|
57
59
|
"""
|
|
58
60
|
Gathers all project context information by orchestrating its dependencies.
|
|
@@ -108,7 +110,7 @@ class ContextService(IGetContextUseCase):
|
|
|
108
110
|
web_cache = {}
|
|
109
111
|
|
|
110
112
|
content = self._format_content(
|
|
111
|
-
repo_tree, scoped_paths, file_contents, git_status
|
|
113
|
+
repo_tree, scoped_paths, file_contents, git_status, session_root
|
|
112
114
|
)
|
|
113
115
|
content_tokens = (
|
|
114
116
|
self._llm_client.get_text_token_count(content) if include_tokens else 0
|
|
@@ -126,6 +128,7 @@ class ContextService(IGetContextUseCase):
|
|
|
126
128
|
total_window=total_window,
|
|
127
129
|
system_prompt_tokens=system_prompt_tokens,
|
|
128
130
|
content_tokens=content_tokens,
|
|
131
|
+
session_root=session_root,
|
|
129
132
|
)
|
|
130
133
|
|
|
131
134
|
def _cap_plan_contents(
|
|
@@ -391,6 +394,7 @@ class ContextService(IGetContextUseCase):
|
|
|
391
394
|
scoped_paths: Dict[str, List[str]],
|
|
392
395
|
file_contents: Dict[str, Optional[str]],
|
|
393
396
|
git_status: Optional[str] = None,
|
|
397
|
+
session_root: Optional[str] = None,
|
|
394
398
|
) -> str:
|
|
395
399
|
"""Formats the main content section of the context report."""
|
|
396
400
|
# Gather all unique paths
|
|
@@ -400,9 +404,10 @@ class ContextService(IGetContextUseCase):
|
|
|
400
404
|
if p not in all_paths:
|
|
401
405
|
all_paths.append(p)
|
|
402
406
|
|
|
403
|
-
# Partition
|
|
404
|
-
|
|
405
|
-
session_paths = [p for p in all_paths if
|
|
407
|
+
# Partition this session's own artifacts from ordinary resources. A path
|
|
408
|
+
# read from another session is a resource, not our own history.
|
|
409
|
+
session_paths = [p for p in all_paths if is_own_session_path(p, session_root)]
|
|
410
|
+
workspace_paths = [p for p in all_paths if p not in session_paths]
|
|
406
411
|
|
|
407
412
|
git_status_body = (
|
|
408
413
|
embed_in_fence(git_status, "")
|
|
@@ -424,7 +429,7 @@ class ContextService(IGetContextUseCase):
|
|
|
424
429
|
|
|
425
430
|
# Prepend Session History section first (after header's System Information)
|
|
426
431
|
session_history_parts = self._format_session_history(
|
|
427
|
-
session_paths, file_contents
|
|
432
|
+
session_paths, file_contents, session_root
|
|
428
433
|
)
|
|
429
434
|
if session_history_parts:
|
|
430
435
|
content_parts = session_history_parts + content_parts
|
|
@@ -514,13 +519,14 @@ class ContextService(IGetContextUseCase):
|
|
|
514
519
|
self,
|
|
515
520
|
session_paths: List[str],
|
|
516
521
|
file_contents: Dict[str, Optional[str]],
|
|
522
|
+
session_root: Optional[str] = None,
|
|
517
523
|
) -> List[str]:
|
|
518
524
|
"""Formats the session history section."""
|
|
519
525
|
if not session_paths:
|
|
520
526
|
return []
|
|
521
527
|
|
|
522
528
|
recognized_session_paths = [
|
|
523
|
-
p for p in session_paths if
|
|
529
|
+
p for p in session_paths if is_session_history_path(p, session_root)
|
|
524
530
|
]
|
|
525
531
|
if not recognized_session_paths:
|
|
526
532
|
return []
|
|
@@ -528,7 +534,7 @@ class ContextService(IGetContextUseCase):
|
|
|
528
534
|
recognized_session_paths.sort(key=get_session_history_sort_key)
|
|
529
535
|
parts = ["\n## Session History"]
|
|
530
536
|
for path in recognized_session_paths:
|
|
531
|
-
disp_name = get_session_history_display_name(path)
|
|
537
|
+
disp_name = get_session_history_display_name(path, session_root)
|
|
532
538
|
content = file_contents.get(path) or ""
|
|
533
539
|
content_str = content.strip()
|
|
534
540
|
lang = get_language_from_path(path)
|
|
@@ -72,12 +72,14 @@ class PlanningService(IPlanningUseCase):
|
|
|
72
72
|
except Exception:
|
|
73
73
|
system_token_count = 0
|
|
74
74
|
|
|
75
|
+
session_root = str(Path(turn_dir).parent)
|
|
75
76
|
context = self._context_service.get_context(
|
|
76
77
|
context_files=resolved_context_files,
|
|
77
78
|
agent_name=agent_name,
|
|
78
79
|
current_turn=Path(turn_dir).name,
|
|
79
80
|
system_prompt_tokens=system_token_count,
|
|
80
|
-
cache_dir=
|
|
81
|
+
cache_dir=session_root,
|
|
82
|
+
session_root=session_root,
|
|
81
83
|
)
|
|
82
84
|
|
|
83
85
|
# Context is purely project state (including initial_request.md via session.context).
|
|
@@ -229,11 +229,42 @@ def embed_in_fence(content: str, lang: str) -> str:
|
|
|
229
229
|
return f"{fence}{lang}\n{sanitized}\n{fence}"
|
|
230
230
|
|
|
231
231
|
|
|
232
|
-
def
|
|
232
|
+
def _normalize_session_path(path: str) -> str:
|
|
233
|
+
"""Normalize a path to POSIX slashes with any leading './' removed."""
|
|
234
|
+
return path.replace("\\", "/").lstrip("./")
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _session_directory_name(session_root: str) -> str:
|
|
238
|
+
"""Return the final path component of a session root (its directory name)."""
|
|
239
|
+
return _normalize_session_path(session_root).rstrip("/").rsplit("/", 1)[-1]
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def is_own_session_path(path: str, session_root: str | None) -> bool:
|
|
243
|
+
"""
|
|
244
|
+
Determines whether ``path`` belongs to the session at ``session_root``.
|
|
245
|
+
|
|
246
|
+
Falls back to the coarse ``is_session_file_path`` test when no root is
|
|
247
|
+
supplied, so legacy callers keep their session-agnostic partition.
|
|
248
|
+
"""
|
|
249
|
+
if not is_session_file_path(path):
|
|
250
|
+
return False
|
|
251
|
+
if not session_root:
|
|
252
|
+
return True
|
|
253
|
+
session_name = _session_directory_name(session_root)
|
|
254
|
+
return session_name in _normalize_session_path(path).split("/")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def get_session_history_display_name(
|
|
258
|
+
path: str, session_root: str | None = None
|
|
259
|
+
) -> str | None:
|
|
233
260
|
"""
|
|
234
261
|
Returns human-readable display name if it's a recognized session history file.
|
|
262
|
+
|
|
263
|
+
When ``session_root`` is supplied, a path outside that session is not history.
|
|
235
264
|
"""
|
|
236
|
-
|
|
265
|
+
if session_root and not is_own_session_path(path, session_root):
|
|
266
|
+
return None
|
|
267
|
+
clean_path = _normalize_session_path(path)
|
|
237
268
|
if "initial_request.md" in clean_path:
|
|
238
269
|
return "Initial Request"
|
|
239
270
|
plan_match = re.search(r"sessions/[^/]+/(\d+)/plan.md$", clean_path)
|
|
@@ -248,22 +279,24 @@ def get_session_history_display_name(path: str) -> str | None:
|
|
|
248
279
|
def is_session_file_path(path: str) -> bool:
|
|
249
280
|
"""
|
|
250
281
|
Determines if a path is inside .teddy/sessions/.
|
|
282
|
+
|
|
283
|
+
Normalizes backslashes first, so a Windows-style path is recognized too.
|
|
251
284
|
"""
|
|
252
|
-
return "sessions/" in path
|
|
285
|
+
return "sessions/" in _normalize_session_path(path)
|
|
253
286
|
|
|
254
287
|
|
|
255
|
-
def is_session_history_path(path: str) -> bool:
|
|
288
|
+
def is_session_history_path(path: str, session_root: str | None = None) -> bool:
|
|
256
289
|
"""
|
|
257
|
-
Determines if a path is a session history file
|
|
290
|
+
Determines if a path is a session history file for ``session_root``.
|
|
258
291
|
"""
|
|
259
|
-
return get_session_history_display_name(path) is not None
|
|
292
|
+
return get_session_history_display_name(path, session_root) is not None
|
|
260
293
|
|
|
261
294
|
|
|
262
295
|
def get_session_history_sort_key(path: str) -> tuple[int, int]:
|
|
263
296
|
"""
|
|
264
297
|
Sort key for chronological session history: (turn_number, sub_order).
|
|
265
298
|
"""
|
|
266
|
-
clean_path = path
|
|
299
|
+
clean_path = _normalize_session_path(path)
|
|
267
300
|
if "initial_request.md" in clean_path:
|
|
268
301
|
return (0, 0)
|
|
269
302
|
plan_match = re.search(r"sessions/[^/]+/(\d+)/plan.md$", clean_path)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|