kiwi-code 0.0.514__tar.gz → 0.0.515__tar.gz
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.
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/PKG-INFO +2 -2
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/pyproject.toml +2 -2
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/client.py +15 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/human_questions.py +22 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/run_activity.py +72 -2
- kiwi_code-0.0.515/src/kiwi_cli/run_links.py +441 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_activity_view.py +193 -9
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_dashboard.py +397 -105
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_dashboard_css.py +20 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_dashboard_helpers.py +1 -1
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_dashboard_widgets.py +48 -6
- kiwi_code-0.0.515/tests/test_history_links.py +163 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_human_questions.py +9 -3
- kiwi_code-0.0.515/tests/test_idle_watch.py +241 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_run_activity.py +21 -18
- kiwi_code-0.0.515/tests/test_run_activity_links.py +119 -0
- kiwi_code-0.0.515/tests/test_run_doc_links.py +71 -0
- kiwi_code-0.0.515/tests/test_run_links.py +247 -0
- kiwi_code-0.0.515/tests/test_run_links_strip.py +139 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_run_steering.py +84 -2
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/uv.lock +5 -5
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/.github/workflows/publish.yml +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/.github/workflows/test.yml +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/.gitignore +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/.python-version +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/Makefile +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/README.md +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/docs/runtime_audit.html +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/docs/social_login_e2e.md +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/scripts/set_edition.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/scripts/ws_auth_check.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/common/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/common/banner.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/_edition.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/auth.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/autocode.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/checkpoints.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/cli.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/commands.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/edition.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/io_threads.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/logger.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/models.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/oauth.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/runtime_manager.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/server.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/subagents.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_cli/terminal_mode.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/__main__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/auth.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/checkpoints.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/cli.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/commands.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/constants.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/batch.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/codelens.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/context.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/edits.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/handler.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/paths.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/read.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/search.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/text.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/upload.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/fs/write.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/handlers.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/link.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/main.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/restricted.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/sessions.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/state.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/tui_bridge.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/ui.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_runtime/uploads.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/attention.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/autoupdate.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/inline_file_picker.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/latex_unicode.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/main.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/random_words.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/role_mode.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/runtime_agent.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/attach_content.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/command_result.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/detach_files.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/file_browser.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/help.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/id_picker.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/login.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/runtime_cleanup.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/runtime_logs.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/slash_picker.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_question_widgets.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_status_line.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/screens/term_subagent_widgets.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/slash_commands.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/status_words.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/term_app.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/terminal_theme.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/ui_settings.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/widgets.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/src/kiwi_tui/worktrees.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/test_hello.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/__init__.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/conftest.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_account_server.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_attention.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_autocode_actions.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_autoupdate.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_batch_fs_tool.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_checkpoints.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_cli_help.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_command_tips.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_copy_path_fs_tool.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_fs_edit_fidelity.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_imports.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_io_threads.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_login_social.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_math_and_tables.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_oauth.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_read_file_streaming.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_reexec_kiwi.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_reply_selection.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_role_mode_injection.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_cleanup_per_account.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_connection.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_edit_diffs.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_fixes.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_imports_on_windows.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_log_trimming.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_runtime_social_login.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_search_in_files_fs_tool.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_slash_commands.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_stats_command.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_status_line.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_subagents.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_term_dashboard_ui.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_terminal_mode.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_terminal_theme.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_toasts.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_tokens.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_tui_interactive_runtime.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_tui_palette.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_unified_diff.py +0 -0
- {kiwi_code-0.0.514 → kiwi_code-0.0.515}/tests/test_worktrees.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: kiwi-code
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.515
|
|
4
4
|
Summary: A textual-based terminal user interface application
|
|
5
5
|
Project-URL: Homepage, https://kiwicode.ai
|
|
6
6
|
Author-email: Anurag <anurag@meetkiwi.co>
|
|
@@ -19,7 +19,7 @@ Requires-Dist: httpx>=0.25.0
|
|
|
19
19
|
Requires-Dist: loguru>=0.7.3
|
|
20
20
|
Requires-Dist: psutil>=5.9.0
|
|
21
21
|
Requires-Dist: pydantic>=2.12.5
|
|
22
|
-
Requires-Dist: pykiwiai==0.0.
|
|
22
|
+
Requires-Dist: pykiwiai==0.0.15
|
|
23
23
|
Requires-Dist: setproctitle>=1.3.0
|
|
24
24
|
Requires-Dist: textual-dev>=1.8.0
|
|
25
25
|
Requires-Dist: textual>=8.1.1
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "kiwi-code"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.515"
|
|
4
4
|
description = "A textual-based terminal user interface application"
|
|
5
5
|
readme = {file = "README.md", content-type = "text/markdown"}
|
|
6
6
|
requires-python = ">=3.11,<4.0"
|
|
7
7
|
dependencies = [
|
|
8
|
-
"pykiwiai==0.0.
|
|
8
|
+
"pykiwiai==0.0.15",
|
|
9
9
|
"loguru>=0.7.3",
|
|
10
10
|
"pydantic>=2.12.5",
|
|
11
11
|
"textual>=8.1.1",
|
|
@@ -559,6 +559,21 @@ class AutobotsClientWrapper:
|
|
|
559
559
|
except Exception:
|
|
560
560
|
pass
|
|
561
561
|
|
|
562
|
+
# Its links to other runs (filled in when the run is read): who messaged it,
|
|
563
|
+
# whom it messaged, who spawned it. See kiwi_cli/run_links.py.
|
|
564
|
+
for key in ("messaged_by", "messaged_runs"):
|
|
565
|
+
links = getattr(result, key, None)
|
|
566
|
+
if isinstance(links, list):
|
|
567
|
+
result_dict[key] = [
|
|
568
|
+
link.to_dict() if hasattr(link, "to_dict") else link for link in links
|
|
569
|
+
]
|
|
570
|
+
for key in ("parent_action_result_id", "parent_name", "run_kind"):
|
|
571
|
+
value = getattr(result, key, None)
|
|
572
|
+
if isinstance(value, str) and value:
|
|
573
|
+
result_dict[key] = value
|
|
574
|
+
elif hasattr(value, "value") and value.value:
|
|
575
|
+
result_dict[key] = str(value.value)
|
|
576
|
+
|
|
562
577
|
questions = getattr(result, "human_questions", None)
|
|
563
578
|
result_dict["human_questions"] = parse_questions(
|
|
564
579
|
[q.to_dict() for q in questions] if isinstance(questions, list) else None
|
|
@@ -153,6 +153,28 @@ def build_answers(
|
|
|
153
153
|
return answers
|
|
154
154
|
|
|
155
155
|
|
|
156
|
+
def answers_text(questions: Iterable[dict[str, Any]], answers: Iterable[dict[str, Any]]) -> str:
|
|
157
|
+
"""The answers in the words the backend gives the agent (`render_answers` in autobots'
|
|
158
|
+
human_question_service.py), without its heading: what the turn your answers start shows
|
|
159
|
+
while it runs, as it reads once the run is read back."""
|
|
160
|
+
asked = {q.get("question_id"): q for q in questions if isinstance(q, dict)}
|
|
161
|
+
lines: list[str] = []
|
|
162
|
+
for answer in answers:
|
|
163
|
+
q = asked.get(answer.get("question_id")) or {}
|
|
164
|
+
chosen = ", ".join(str(s) for s in answer.get("selected") or [])
|
|
165
|
+
text = str(answer.get("text") or "")
|
|
166
|
+
if answer.get("skip"):
|
|
167
|
+
reply = "skipped by the user; use your best judgment"
|
|
168
|
+
elif chosen and text:
|
|
169
|
+
reply = f'{chosen}. They added: "{text}"'
|
|
170
|
+
elif chosen or text:
|
|
171
|
+
reply = chosen or f'"{text}"'
|
|
172
|
+
else:
|
|
173
|
+
reply = "answered with the attachments below"
|
|
174
|
+
lines.append(f'- "{q.get("question") or ""}": {reply}')
|
|
175
|
+
return "\n".join(lines)
|
|
176
|
+
|
|
177
|
+
|
|
156
178
|
def can_submit(questions: Iterable[dict[str, Any]], drafts: dict[str, QuestionDraft]) -> bool:
|
|
157
179
|
"""Every pending card is answered (validly) or skipped: one call handles them all."""
|
|
158
180
|
pending = [q for q in questions if q.get("status") == PENDING]
|
|
@@ -4,7 +4,9 @@ happened (text, tool calls, notices and thinking in order), then one summary lin
|
|
|
4
4
|
|
|
5
5
|
The stream sends one JSON event per message: `turn.started/finished`, `step.started`,
|
|
6
6
|
`text.delta`, `reasoning.delta`, `tool.started/args.delta/ready/running/finished`,
|
|
7
|
-
`notice`,
|
|
7
|
+
`notice`, and what reached the turn or left it: `instruction.received` (a line among its
|
|
8
|
+
steps, or yours marked read) and `agent.message.sent` (on the agent_bridge call that sent
|
|
9
|
+
it); plus `subagent.*` and `question.*`, which other parts of the TUI handle. A
|
|
8
10
|
client that connects late reads the run's recent events back first
|
|
9
11
|
(`GET /v1/server_sent_events/activity/{run_id}`); that read-back and the live stream
|
|
10
12
|
overlap, so an event already seen (same `src` and `seq`) is dropped.
|
|
@@ -21,6 +23,8 @@ from collections import deque
|
|
|
21
23
|
from dataclasses import dataclass, field
|
|
22
24
|
from typing import Iterable
|
|
23
25
|
|
|
26
|
+
from kiwi_cli.run_links import Aside, SentMessage, aside_of, aside_words, bridge_line
|
|
27
|
+
|
|
24
28
|
#: Sent only by the process running a turn. While a turn is open, these from another
|
|
25
29
|
#: process are an earlier attempt's (the backend retried the turn while it still ran).
|
|
26
30
|
TURN_OWN = frozenset({
|
|
@@ -66,6 +70,23 @@ class ToolLine:
|
|
|
66
70
|
#: The changes it made to files, as the user's runtime recorded them: path, added,
|
|
67
71
|
#: removed, diff (unified, without its header), truncated, created, deleted.
|
|
68
72
|
edits: list[dict] = field(default_factory=list)
|
|
73
|
+
#: An agent_bridge call: the arguments that say what it does (operation, run), and,
|
|
74
|
+
#: once it sent a message, to whom and how it was delivered (`agent.message.sent`).
|
|
75
|
+
bridge_args: dict | None = None
|
|
76
|
+
sent: SentMessage | None = None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
#: The arguments of an agent_bridge call kept to word its line.
|
|
80
|
+
_BRIDGE_KEYS = ("operation", "action_run_id", "action_id")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class AsideItem:
|
|
85
|
+
"""Something that reached the turn while it ran, among its steps (see run_links.py)."""
|
|
86
|
+
|
|
87
|
+
kind = "aside"
|
|
88
|
+
aside: Aside
|
|
89
|
+
id: int = 0
|
|
69
90
|
|
|
70
91
|
|
|
71
92
|
@dataclass
|
|
@@ -94,10 +115,18 @@ class TurnView:
|
|
|
94
115
|
#: How much of that text the screen has revealed so far: text arrives in bursts, and
|
|
95
116
|
#: the screen shows it at a steady pace. None (the default) shows it all.
|
|
96
117
|
revealed: int | None = None
|
|
118
|
+
#: The instructions you sent that the turn has read, by their text.
|
|
119
|
+
read: list[str] = field(default_factory=list)
|
|
97
120
|
_with_args: deque = field(default_factory=deque, repr=False)
|
|
98
121
|
_thoughts: deque = field(default_factory=deque, repr=False)
|
|
99
122
|
_blocks: int = 0
|
|
100
123
|
|
|
124
|
+
def new_aside(self, aside: Aside) -> AsideItem:
|
|
125
|
+
self._blocks += 1
|
|
126
|
+
item = AsideItem(aside=aside, id=self._blocks)
|
|
127
|
+
self._add(item)
|
|
128
|
+
return item
|
|
129
|
+
|
|
101
130
|
def new_block(self, kind: str, step: int | None) -> "Block":
|
|
102
131
|
self._blocks += 1
|
|
103
132
|
block = Block(kind=kind, step=step, id=self._blocks)
|
|
@@ -131,7 +160,7 @@ class TurnView:
|
|
|
131
160
|
|
|
132
161
|
@property
|
|
133
162
|
def steps_key(self) -> str:
|
|
134
|
-
"""What
|
|
163
|
+
"""What folds this turn's steps away on screen, and back."""
|
|
135
164
|
return f"steps:{self.key[0]}:{self.key[1]}"
|
|
136
165
|
|
|
137
166
|
@property
|
|
@@ -235,6 +264,11 @@ def describe(event: dict) -> str:
|
|
|
235
264
|
if kind.startswith("question."):
|
|
236
265
|
n = len(event.get("questions") or event.get("question_ids") or [])
|
|
237
266
|
return _one_line(f"{n} question{'s' if n != 1 else ''}" + (f" · {event['status']}" if event.get("status") else ""))
|
|
267
|
+
if kind == "instruction.received":
|
|
268
|
+
sender = f" from {event['name']}" if event.get("name") else ""
|
|
269
|
+
return _one_line(f"{event.get('kind') or ''}{sender} · {event.get('text') or ''}")
|
|
270
|
+
if kind in ("agent.message.sent", "agent.message.received"):
|
|
271
|
+
return _one_line(f"{event.get('name') or event.get('peer_run_id') or ''} · {event.get('delivered_as') or ''}")
|
|
238
272
|
if kind == "step.started":
|
|
239
273
|
return f"step {event.get('step')}"
|
|
240
274
|
if kind == "turn.started":
|
|
@@ -459,6 +493,24 @@ class RunActivityView:
|
|
|
459
493
|
)
|
|
460
494
|
self._add_turn(self._open)
|
|
461
495
|
return
|
|
496
|
+
if kind == "instruction.received":
|
|
497
|
+
turn = self._turn_for(event)
|
|
498
|
+
aside = aside_of(event)
|
|
499
|
+
if aside is not None:
|
|
500
|
+
turn.new_aside(aside)
|
|
501
|
+
elif str(event.get("text") or "").strip():
|
|
502
|
+
turn.read.append(str(event["text"]).strip())
|
|
503
|
+
return
|
|
504
|
+
if kind == "agent.message.sent":
|
|
505
|
+
tool = self._open.tools.get(str(event.get("call_id") or "")) if self._open is not None else None
|
|
506
|
+
if tool is not None:
|
|
507
|
+
tool.sent = SentMessage(
|
|
508
|
+
run_id=str(event.get("peer_run_id") or ""),
|
|
509
|
+
name=str(event.get("name") or ""),
|
|
510
|
+
delivered_as=str(event.get("delivered_as") or ""),
|
|
511
|
+
)
|
|
512
|
+
_word_bridge_call(tool)
|
|
513
|
+
return
|
|
462
514
|
if kind not in TURN_OWN and kind != "notice":
|
|
463
515
|
return
|
|
464
516
|
turn = self._turn_for(event)
|
|
@@ -521,6 +573,8 @@ class RunActivityView:
|
|
|
521
573
|
tool.hosted = True
|
|
522
574
|
if kind == "tool.ready":
|
|
523
575
|
turn.keep_args(tool, event.get("args"), event.get("args_chars"), event.get("args_truncated"))
|
|
576
|
+
if tool.name == "agent_bridge":
|
|
577
|
+
tool.bridge_args = _bridge_args(event.get("args"))
|
|
524
578
|
if tool.state == "forming":
|
|
525
579
|
tool.state = "ready"
|
|
526
580
|
elif kind == "tool.running":
|
|
@@ -530,3 +584,19 @@ class RunActivityView:
|
|
|
530
584
|
tool.error = str(event.get("error") or "")
|
|
531
585
|
tool.duration_ms = event.get("duration_ms")
|
|
532
586
|
tool.note = ""
|
|
587
|
+
if tool.name == "agent_bridge":
|
|
588
|
+
_word_bridge_call(tool)
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def _bridge_args(args: object) -> dict | None:
|
|
592
|
+
"""What an agent_bridge call's arguments say it does (operation, run), from the
|
|
593
|
+
server's preview of them, which is an object (`_args_preview` in the backend)."""
|
|
594
|
+
if not isinstance(args, dict):
|
|
595
|
+
return None
|
|
596
|
+
kept = {k: args[k] for k in _BRIDGE_KEYS if isinstance(args.get(k), str)}
|
|
597
|
+
return kept or None
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def _word_bridge_call(tool: ToolLine) -> None:
|
|
601
|
+
"""An agent_bridge call's line in words ("⇄ messaged Coder · started a new task")."""
|
|
602
|
+
tool.label = f"⇄ {aside_words(bridge_line(tool.bridge_args, tool.sent))}"
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"""Who started a turn, what reached it while it ran, and which runs it is linked to: the
|
|
2
|
+
agent bridge (AUT-1765), run instructions (AUT-1783) and subagents, read from what the
|
|
3
|
+
backend gives. The VS Code extension reads the same (its `src/chat/runLinks.ts`).
|
|
4
|
+
|
|
5
|
+
- **A turn's origin** comes from its input's `source` (`agent_message`, `subagent`,
|
|
6
|
+
`human_answer`, `schedule`, ...), with `sender_name` / `sender_run_id` beside it. The
|
|
7
|
+
input text of a turn the server opened is framed for the model ("Message from agent
|
|
8
|
+
..."); `origin_of` takes the framing off so a person reads only the message.
|
|
9
|
+
- **What reached a turn while it ran** is its `instructions` once it is finished, and
|
|
10
|
+
`instruction.received` events while it runs.
|
|
11
|
+
- **Links between runs** are `messaged_by` / `messaged_runs` on every run, and its parent.
|
|
12
|
+
|
|
13
|
+
Nothing here is worked out from free text that the backend also gives as a field.
|
|
14
|
+
Nothing here talks to the network or draws anything.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import re
|
|
20
|
+
from dataclasses import dataclass, field
|
|
21
|
+
from datetime import datetime
|
|
22
|
+
|
|
23
|
+
# ---- shapes ----
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class RunRef:
|
|
28
|
+
"""Another run, by name, with its id when there is one to open."""
|
|
29
|
+
|
|
30
|
+
name: str
|
|
31
|
+
run_id: str | None = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class TurnOrigin:
|
|
36
|
+
"""Who started a turn, when it was not you.
|
|
37
|
+
|
|
38
|
+
kind:
|
|
39
|
+
- ``agent``: another agent's message, through agent_bridge; `sources` says who.
|
|
40
|
+
- ``subagents``: the results or reports of subagents this run spawned; `count` of them.
|
|
41
|
+
- ``answers``: your answers to the questions the agent asked.
|
|
42
|
+
- ``source``: anything else (a schedule, a webhook, a chat app, ...); `label` says it.
|
|
43
|
+
`text` is what was said, without the framing; empty while nothing is known yet.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
kind: str
|
|
47
|
+
text: str = ""
|
|
48
|
+
sources: list[RunRef] = field(default_factory=list)
|
|
49
|
+
count: int = 0
|
|
50
|
+
label: str = ""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class MyInstruction:
|
|
55
|
+
"""An instruction you sent to a turn while it ran: sending; taken by the server
|
|
56
|
+
(`sent`); read by the agent (`read`)."""
|
|
57
|
+
|
|
58
|
+
text: str
|
|
59
|
+
state: str = "sending"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class Aside:
|
|
64
|
+
"""One line among a turn's steps: something that reached it, or a message it sent.
|
|
65
|
+
|
|
66
|
+
`icon` is one of ⇄ (agents talking), ⎇ (subagents), ↳ (instructions), ? (answers).
|
|
67
|
+
`text` is the words before the name, or all of it when there is no name; `after`
|
|
68
|
+
follows the name ("started a new task"); `quote` is what was said, under the line.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
icon: str
|
|
72
|
+
text: str
|
|
73
|
+
ref: RunRef | None = None
|
|
74
|
+
after: str = ""
|
|
75
|
+
quote: str = ""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass
|
|
79
|
+
class LinkView:
|
|
80
|
+
run_id: str
|
|
81
|
+
name: str
|
|
82
|
+
at: str = "" # ISO time
|
|
83
|
+
delivered_as: str = ""
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass
|
|
87
|
+
class RunLinksView:
|
|
88
|
+
"""Who messaged this run, whom it messaged, its parent."""
|
|
89
|
+
|
|
90
|
+
messaged_by: list[LinkView] = field(default_factory=list)
|
|
91
|
+
messaged: list[LinkView] = field(default_factory=list)
|
|
92
|
+
parent: RunRef | None = None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass
|
|
96
|
+
class SentMessage:
|
|
97
|
+
"""What a sent message reported (`agent.message.sent`), kept on its tool line."""
|
|
98
|
+
|
|
99
|
+
run_id: str
|
|
100
|
+
name: str
|
|
101
|
+
delivered_as: str
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# ---- the framings the backend puts around an instruction (run_instructions.py `_framed`) ----
|
|
105
|
+
|
|
106
|
+
_AGENT_FRAME = re.compile(
|
|
107
|
+
r'Message from agent "([^"]*)" \(run ([^)\s]*)\): ([\s\S]*?)\n'
|
|
108
|
+
r"Reply with agent_bridge send_message to run \S+ only if an answer is needed\."
|
|
109
|
+
)
|
|
110
|
+
SUBAGENT_RESULTS = "Results from the subagents you spawned:"
|
|
111
|
+
_SUBAGENT_REPORT = re.compile(r'^Message from your subagent "([^"]*)": ')
|
|
112
|
+
ANSWERS = "The user answered your questions:"
|
|
113
|
+
USER_FRAME = "User instruction received while you were working: "
|
|
114
|
+
PARENT_FRAME = "Instruction from the agent that spawned you: "
|
|
115
|
+
_STEERING = re.compile(
|
|
116
|
+
r"\nIf it is about your current task, apply it to that task and continue\.\n"
|
|
117
|
+
r"If it is a separate task, hand it to a subagent if you can spawn subagents; "
|
|
118
|
+
r"otherwise do it yourself as well\.\s*$"
|
|
119
|
+
)
|
|
120
|
+
_ATTACHED = re.compile(r"\nAttached files: [^\n]*$")
|
|
121
|
+
#: Where one framed instruction starts, when several were joined into one turn's input.
|
|
122
|
+
_PART_START = re.compile(
|
|
123
|
+
r'\n\n(?=Message from agent "|Results from the subagents you spawned:|Message from your subagent "|'
|
|
124
|
+
r"The user answered your questions:|User instruction received while you were working: |"
|
|
125
|
+
r"Instruction from the agent that spawned you: )"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
SOURCE_LABELS = {
|
|
129
|
+
"schedule": "scheduled",
|
|
130
|
+
"webhook": "from a webhook",
|
|
131
|
+
"chat": "from a chat app",
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _str(value: object) -> str:
|
|
136
|
+
return value if isinstance(value, str) else ""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _bare(text: str) -> str:
|
|
140
|
+
"""One instruction's text without what was appended for the model."""
|
|
141
|
+
return _ATTACHED.sub("", _STEERING.sub("", text)).strip()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def short_id(run_id: str) -> str:
|
|
145
|
+
"""A run id short enough for a line: `6912…ab`."""
|
|
146
|
+
return run_id if len(run_id) <= 10 else f"{run_id[:4]}…{run_id[-2:]}"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _framed_parts(raw: str) -> list[tuple[str, str, RunRef | None]] | None:
|
|
150
|
+
"""A turn's input made of several framed instructions, as (kind, text, sender); None
|
|
151
|
+
when it does not start with one. The server joins what waited while the run was busy
|
|
152
|
+
into one turn (`leftovers.py`), with `source: api` when the kinds differ."""
|
|
153
|
+
parts = _PART_START.split(raw)
|
|
154
|
+
out: list[tuple[str, str, RunRef | None]] = []
|
|
155
|
+
for part in parts:
|
|
156
|
+
m = _AGENT_FRAME.match(part)
|
|
157
|
+
if m:
|
|
158
|
+
out.append(("agent_message", _bare(m.group(3)), RunRef(m.group(1) or "an agent", m.group(2) or None)))
|
|
159
|
+
elif part.startswith(SUBAGENT_RESULTS):
|
|
160
|
+
out.append(("subagent_result", _bare(part[len(SUBAGENT_RESULTS):]), None))
|
|
161
|
+
elif _SUBAGENT_REPORT.match(part):
|
|
162
|
+
m2 = _SUBAGENT_REPORT.match(part)
|
|
163
|
+
out.append(("subagent_report", _bare(part[m2.end():]), RunRef(m2.group(1) or "a subagent")))
|
|
164
|
+
elif part.startswith(ANSWERS):
|
|
165
|
+
out.append(("human_answer", _bare(part[len(ANSWERS):]), None))
|
|
166
|
+
elif part.startswith(USER_FRAME):
|
|
167
|
+
out.append(("user", _bare(part[len(USER_FRAME):]), None))
|
|
168
|
+
elif part.startswith(PARENT_FRAME):
|
|
169
|
+
out.append(("parent_instruction", _bare(part[len(PARENT_FRAME):]), None))
|
|
170
|
+
elif not out:
|
|
171
|
+
return None # not framed: what someone typed
|
|
172
|
+
else:
|
|
173
|
+
# Text after a framed part that is not itself framed: it belongs to that part.
|
|
174
|
+
kind, text, sender = out[-1]
|
|
175
|
+
out[-1] = (kind, f"{text}\n\n{part.strip()}".strip(), sender)
|
|
176
|
+
return out or None
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
_PART_WORDS = {
|
|
180
|
+
"agent_message": "⇄ from {name}",
|
|
181
|
+
"subagent_result": "⎇ subagent results",
|
|
182
|
+
"subagent_report": "⎇ report from {name}",
|
|
183
|
+
"human_answer": "? your answers",
|
|
184
|
+
"user": "↳ your instruction",
|
|
185
|
+
"parent_instruction": "↳ from the agent that spawned it",
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def origin_of(input_block: object) -> tuple[TurnOrigin | None, str]:
|
|
190
|
+
"""Who started a turn, and what to show of its input: (origin, text). `origin` is None
|
|
191
|
+
for a turn you started; `text` is then what you sent (a message you sent while a turn
|
|
192
|
+
ran, which the server made a turn of its own, without its framing)."""
|
|
193
|
+
inp = input_block if isinstance(input_block, dict) else {}
|
|
194
|
+
raw = _str(inp.get("text"))
|
|
195
|
+
source = _str(inp.get("source"))
|
|
196
|
+
if source == "agent_message":
|
|
197
|
+
sources: list[RunRef] = []
|
|
198
|
+
said: list[str] = []
|
|
199
|
+
for m in _AGENT_FRAME.finditer(raw):
|
|
200
|
+
if not any(s.run_id == m.group(2) for s in sources):
|
|
201
|
+
sources.append(RunRef(m.group(1) or "an agent", m.group(2) or None))
|
|
202
|
+
said.append(_bare(m.group(3)))
|
|
203
|
+
name = _str(inp.get("sender_name"))
|
|
204
|
+
run_id = _str(inp.get("sender_run_id"))
|
|
205
|
+
# The server names the sender when there was one; it outranks what the text says.
|
|
206
|
+
if name or run_id:
|
|
207
|
+
sources = [RunRef(name or "an agent", run_id or None)]
|
|
208
|
+
return TurnOrigin("agent", text="\n\n".join(said) if said else _bare(raw), sources=sources), ""
|
|
209
|
+
if source == "subagent":
|
|
210
|
+
ids = inp.get("subagent_run_ids")
|
|
211
|
+
count = len(ids) if isinstance(ids, list) else 0
|
|
212
|
+
pieces = re.split(r'\n\n(?=Results from the subagents you spawned:|Message from your subagent ")', raw)
|
|
213
|
+
text = "\n\n".join(
|
|
214
|
+
_bare(p[len(SUBAGENT_RESULTS):] if p.startswith(SUBAGENT_RESULTS) else _SUBAGENT_REPORT.sub(r"\1: ", p))
|
|
215
|
+
for p in pieces
|
|
216
|
+
)
|
|
217
|
+
return TurnOrigin("subagents", text=text, count=count), ""
|
|
218
|
+
if source == "human_answer":
|
|
219
|
+
return TurnOrigin("answers", text=_bare(raw[len(ANSWERS):] if raw.startswith(ANSWERS) else raw)), ""
|
|
220
|
+
if source in SOURCE_LABELS:
|
|
221
|
+
return TurnOrigin("source", text=raw, label=SOURCE_LABELS[source]), ""
|
|
222
|
+
parts = _framed_parts(raw)
|
|
223
|
+
if parts:
|
|
224
|
+
if all(kind == "user" for kind, _, _ in parts):
|
|
225
|
+
# Yours: what you sent while a turn ran, which became a turn of its own.
|
|
226
|
+
return None, "\n\n".join(text for _, text, _ in parts if text)
|
|
227
|
+
if len(parts) == 1 and parts[0][0] == "parent_instruction":
|
|
228
|
+
# A subagent's parent steered it after its turn ended: the parent started this one.
|
|
229
|
+
return TurnOrigin("source", text=parts[0][1], label="instruction from the agent that spawned it"), ""
|
|
230
|
+
# Several kinds waited while the run was busy and became one turn.
|
|
231
|
+
lines = []
|
|
232
|
+
for kind, text, sender in parts:
|
|
233
|
+
head = _PART_WORDS.get(kind, "↳ " + kind.replace("_", " ")).format(name=sender.name if sender else "an agent")
|
|
234
|
+
lines.append(f"{head}: {text}" if text else head)
|
|
235
|
+
return TurnOrigin("source", text="\n\n".join(lines), label="messages that came in while it was busy"), ""
|
|
236
|
+
return None, raw
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def delivered_text(delivered_as: object) -> str:
|
|
240
|
+
"""How an agent's message reached its run, in words."""
|
|
241
|
+
if delivered_as == "turn":
|
|
242
|
+
return "started a new task"
|
|
243
|
+
if delivered_as == "instruct":
|
|
244
|
+
return "read while working"
|
|
245
|
+
return ""
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def aside_of(instruction: object) -> Aside | None:
|
|
249
|
+
"""One instruction a turn read (a turn row's `instructions` item, or an
|
|
250
|
+
`instruction.received` event), as a line among its steps; None for yours, which is
|
|
251
|
+
shown under what you sent instead (`MyInstruction`)."""
|
|
252
|
+
i = instruction if isinstance(instruction, dict) else {}
|
|
253
|
+
kind = _str(i.get("kind"))
|
|
254
|
+
text = _str(i.get("text")).strip()
|
|
255
|
+
name = _str(i.get("sender")) or _str(i.get("name"))
|
|
256
|
+
run_id = _str(i.get("sender_run_id")) or _str(i.get("peer_run_id"))
|
|
257
|
+
ref = RunRef(name or "an agent", run_id or None) if (name or run_id) else None
|
|
258
|
+
if kind in ("user", ""):
|
|
259
|
+
return None
|
|
260
|
+
if kind == "agent_message":
|
|
261
|
+
return Aside("⇄", "message from", ref=ref or RunRef("an agent"), quote=text)
|
|
262
|
+
if kind == "subagent_result":
|
|
263
|
+
ids = i.get("subagent_run_ids")
|
|
264
|
+
n = len(ids) if isinstance(ids, list) else 0
|
|
265
|
+
return Aside("⎇", f"results from {n} subagents" if n > 1 else "a subagent's results", quote=text)
|
|
266
|
+
if kind == "subagent_report":
|
|
267
|
+
if ref:
|
|
268
|
+
return Aside("⎇", "report from", ref=ref, quote=text)
|
|
269
|
+
return Aside("⎇", "a subagent reported", quote=text)
|
|
270
|
+
if kind == "parent_instruction":
|
|
271
|
+
return Aside("↳", "instruction from the agent that spawned it", quote=text)
|
|
272
|
+
if kind == "human_answer":
|
|
273
|
+
return Aside("?", "your answers", quote=text)
|
|
274
|
+
return Aside("↳", kind.replace("_", " "), quote=text)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def instructions_of(items: object) -> tuple[list[MyInstruction], list[Aside]]:
|
|
278
|
+
"""A finished turn's instructions: yours (shown read) and the rest as lines."""
|
|
279
|
+
mine: list[MyInstruction] = []
|
|
280
|
+
asides: list[Aside] = []
|
|
281
|
+
for i in items if isinstance(items, list) else []:
|
|
282
|
+
if not isinstance(i, dict):
|
|
283
|
+
continue
|
|
284
|
+
aside = aside_of(i)
|
|
285
|
+
if aside is not None:
|
|
286
|
+
asides.append(aside)
|
|
287
|
+
elif _str(i.get("text")).strip():
|
|
288
|
+
mine.append(MyInstruction(_str(i.get("text")).strip(), "read"))
|
|
289
|
+
return mine, asides
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _json_object(value: object) -> dict | None:
|
|
293
|
+
if isinstance(value, dict):
|
|
294
|
+
return value
|
|
295
|
+
if not isinstance(value, str) or not value.strip():
|
|
296
|
+
return None
|
|
297
|
+
try:
|
|
298
|
+
parsed = json.loads(value)
|
|
299
|
+
except (TypeError, ValueError):
|
|
300
|
+
return None
|
|
301
|
+
return parsed if isinstance(parsed, dict) else None
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def sent_asides(tool_calls: object) -> list[Aside]:
|
|
305
|
+
"""The messages a finished turn sent through agent_bridge, from its tool calls."""
|
|
306
|
+
out: list[Aside] = []
|
|
307
|
+
for call in tool_calls if isinstance(tool_calls, list) else []:
|
|
308
|
+
if not isinstance(call, dict) or call.get("name") != "agent_bridge":
|
|
309
|
+
continue
|
|
310
|
+
args = _json_object(call.get("input"))
|
|
311
|
+
if not args or args.get("operation") != "send_message":
|
|
312
|
+
continue
|
|
313
|
+
result = _json_object(call.get("output"))
|
|
314
|
+
run_id = _str((result or {}).get("run_id")) or _str(args.get("action_run_id"))
|
|
315
|
+
if not run_id and not result:
|
|
316
|
+
continue
|
|
317
|
+
name = _str((result or {}).get("name")) or (f"run {short_id(run_id)}" if run_id else "a run")
|
|
318
|
+
out.append(Aside(
|
|
319
|
+
"⇄", "messaged",
|
|
320
|
+
ref=RunRef(name, run_id or None),
|
|
321
|
+
after=delivered_text((result or {}).get("delivered_as")),
|
|
322
|
+
quote=_str(args.get("message")).strip(),
|
|
323
|
+
))
|
|
324
|
+
return out
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def bridge_line(args: object, sent: SentMessage | None = None) -> Aside:
|
|
328
|
+
"""An agent_bridge call in a person's words: "messaged Coder · started a new task",
|
|
329
|
+
"read run 6912…ab". From its arguments (the server's preview: an object, or JSON text
|
|
330
|
+
possibly cut short) and, for a message, what the send reported."""
|
|
331
|
+
obj = _json_object(args)
|
|
332
|
+
text = args if isinstance(args, str) else ""
|
|
333
|
+
|
|
334
|
+
def get(key: str) -> str:
|
|
335
|
+
value = _str((obj or {}).get(key))
|
|
336
|
+
if value:
|
|
337
|
+
return value
|
|
338
|
+
m = re.search(rf'"{key}"\s*:\s*"([^"]*)"', text)
|
|
339
|
+
return m.group(1) if m else ""
|
|
340
|
+
|
|
341
|
+
operation = get("operation")
|
|
342
|
+
run_id = get("action_run_id")
|
|
343
|
+
run = RunRef(f"run {short_id(run_id)}", run_id) if run_id else None
|
|
344
|
+
if operation == "send_message":
|
|
345
|
+
if sent is not None:
|
|
346
|
+
return Aside("⇄", "messaged", ref=RunRef(sent.name or f"run {short_id(sent.run_id)}", sent.run_id or None),
|
|
347
|
+
after=delivered_text(sent.delivered_as))
|
|
348
|
+
return Aside("⇄", "messaging", ref=run) if run else Aside("⇄", "sending a message")
|
|
349
|
+
if operation == "get_run":
|
|
350
|
+
return Aside("⇄", "read", ref=run) if run else Aside("⇄", "reading a run")
|
|
351
|
+
if operation == "get_live_update":
|
|
352
|
+
return Aside("⇄", "checked what is happening in", ref=run) if run else Aside("⇄", "checking a run")
|
|
353
|
+
if operation == "get_action":
|
|
354
|
+
return Aside("⇄", "read an agent's settings")
|
|
355
|
+
return Aside("⇄", "agent bridge")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def aside_words(aside: Aside) -> str:
|
|
359
|
+
"""An aside as one plain line, without its mark: "messaged Coder · started a new task"."""
|
|
360
|
+
out = aside.text
|
|
361
|
+
if aside.ref is not None:
|
|
362
|
+
out += f" {aside.ref.name}"
|
|
363
|
+
if aside.after:
|
|
364
|
+
out += f" · {aside.after}"
|
|
365
|
+
return out
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _link_list(items: object) -> list[LinkView]:
|
|
369
|
+
out: list[LinkView] = []
|
|
370
|
+
for link in items if isinstance(items, list) else []:
|
|
371
|
+
if not isinstance(link, dict):
|
|
372
|
+
continue
|
|
373
|
+
run_id = _str(link.get("run_id"))
|
|
374
|
+
if not run_id:
|
|
375
|
+
continue
|
|
376
|
+
at = link.get("at")
|
|
377
|
+
out.append(LinkView(
|
|
378
|
+
run_id=run_id,
|
|
379
|
+
name=_str(link.get("name")) or f"run {short_id(run_id)}",
|
|
380
|
+
at=at.isoformat() if isinstance(at, datetime) else _str(at),
|
|
381
|
+
delivered_as=_str(link.get("delivered_as")),
|
|
382
|
+
))
|
|
383
|
+
return out
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _latest_each(links: list[LinkView]) -> list[LinkView]:
|
|
387
|
+
"""Each run once, by its latest message."""
|
|
388
|
+
out: list[LinkView] = []
|
|
389
|
+
for link in links:
|
|
390
|
+
out = [m for m in out if m.run_id != link.run_id]
|
|
391
|
+
out.append(link)
|
|
392
|
+
return out
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def links_of(doc: object) -> RunLinksView | None:
|
|
396
|
+
"""The links of a run document (`GET /v1/action_results/{id}`), or None when it has none."""
|
|
397
|
+
d = doc if isinstance(doc, dict) else {}
|
|
398
|
+
messaged_by = _latest_each(_link_list(d.get("messaged_by")))
|
|
399
|
+
messaged = _latest_each(_link_list(d.get("messaged_runs")))
|
|
400
|
+
parent_id = _str(d.get("parent_action_result_id"))
|
|
401
|
+
parent = RunRef(_str(d.get("parent_name")) or f"run {short_id(parent_id)}", parent_id) if parent_id else None
|
|
402
|
+
if not messaged_by and not messaged and parent is None:
|
|
403
|
+
return None
|
|
404
|
+
return RunLinksView(messaged_by=messaged_by, messaged=messaged, parent=parent)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def link_badge(doc: object) -> str:
|
|
408
|
+
"""What a run list row says about agent messages: "⇄ from Planner", "⇄ sent to 2 runs"."""
|
|
409
|
+
d = doc if isinstance(doc, dict) else {}
|
|
410
|
+
sent_by = _link_list(d.get("messaged_by"))
|
|
411
|
+
if sent_by:
|
|
412
|
+
return f"⇄ from {sent_by[-1].name}"
|
|
413
|
+
n = len({link.run_id for link in _link_list(d.get("messaged_runs"))})
|
|
414
|
+
return f"⇄ sent to {n} run{'' if n == 1 else 's'}" if n else ""
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def clock_time(iso: str, now: datetime | None = None) -> str:
|
|
418
|
+
""""10:41" in local time, or "Nov 3" when not today; "" when it cannot be read."""
|
|
419
|
+
if not iso:
|
|
420
|
+
return ""
|
|
421
|
+
try:
|
|
422
|
+
when = datetime.fromisoformat(iso.replace("Z", "+00:00"))
|
|
423
|
+
except ValueError:
|
|
424
|
+
return ""
|
|
425
|
+
if when.tzinfo is not None:
|
|
426
|
+
when = when.astimezone()
|
|
427
|
+
now = now or datetime.now(when.tzinfo)
|
|
428
|
+
if when.date() == now.date():
|
|
429
|
+
return when.strftime("%H:%M")
|
|
430
|
+
return f"{when.strftime('%b')} {when.day}"
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def turn_extras(item: object) -> tuple[TurnOrigin | None, str, list[MyInstruction], list[Aside]]:
|
|
434
|
+
"""What a stored turn (`result.results[i]`) says beyond its input and output: who
|
|
435
|
+
started it, the text of its input to show, your instructions it read, and the lines
|
|
436
|
+
for what reached it and the messages it sent."""
|
|
437
|
+
d = item if isinstance(item, dict) else {}
|
|
438
|
+
origin, text = origin_of(d.get("input"))
|
|
439
|
+
mine, asides = instructions_of(d.get("instructions"))
|
|
440
|
+
asides.extend(sent_asides(d.get("tool_calls")))
|
|
441
|
+
return origin, text, mine, asides
|