getapo 0.3.1__tar.gz → 0.3.2__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.
- {getapo-0.3.1/src/getapo.egg-info → getapo-0.3.2}/PKG-INFO +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/__init__.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/changelog.py +95 -23
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/claude_runtime.py +45 -13
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/db.py +166 -8
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/resources/guide.md +37 -33
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/app.py +307 -154
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/app.css +51 -3
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/app.js +38 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/now.js +2 -2
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/palette.js +26 -6
- getapo-0.3.2/src/apo/web/templates/_agents_board.html +65 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_bulk.html +1 -0
- getapo-0.3.2/src/apo/web/templates/_decision_log.html +31 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_macros.html +6 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_merge_result.html +1 -1
- getapo-0.3.2/src/apo/web/templates/_new_work.html +86 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_now_item.html +24 -2
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_project_macros.html +14 -1
- getapo-0.3.2/src/apo/web/templates/_reply_form.html +20 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_session_card.html +6 -1
- getapo-0.3.1/src/apo/web/templates/week.html → getapo-0.3.2/src/apo/web/templates/_week_overview.html +9 -29
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_work_location.html +4 -2
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_work_main.html +15 -2
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_work_status.html +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/accept.html +5 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/all_activity.html +1 -0
- getapo-0.3.2/src/apo/web/templates/all_agents.html +42 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/all_overview.html +0 -1
- getapo-0.3.2/src/apo/web/templates/all_work.html +25 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/base.html +9 -4
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/decision.html +32 -6
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/now.html +29 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/outcome.html +63 -41
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/project_activity.html +1 -0
- getapo-0.3.2/src/apo/web/templates/project_agents.html +11 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/project_overview.html +13 -33
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/project_settings.html +28 -16
- getapo-0.3.2/src/apo/web/templates/project_work.html +28 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/projects_shell.html +2 -2
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/report.html +1 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/session.html +50 -22
- {getapo-0.3.1 → getapo-0.3.2/src/getapo.egg-info}/PKG-INFO +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/src/getapo.egg-info/SOURCES.txt +17 -4
- getapo-0.3.2/tests/test_agents_hub.py +89 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_app.py +20 -23
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_autonomy_rules.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_background.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_browser.py +104 -2
- getapo-0.3.2/tests/test_bulk_and_keys.py +45 -0
- getapo-0.3.2/tests/test_claude_profiles.py +310 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_close_rows.py +1 -2
- getapo-0.3.2/tests/test_consolidation.py +84 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_continue.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_entry_points.py +1 -1
- getapo-0.3.2/tests/test_goal_page.py +31 -0
- getapo-0.3.2/tests/test_landing.py +113 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_layout_fixes.py +4 -2
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_linear_goals.py +10 -2
- getapo-0.3.2/tests/test_links.py +141 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_merge_branches.py +199 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_navigation.py +4 -4
- getapo-0.3.2/tests/test_next_item.py +55 -0
- getapo-0.3.2/tests/test_now_scan.py +45 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_overview_order.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_project_home.py +2 -2
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_project_scope.py +8 -8
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_project_settings.py +61 -0
- getapo-0.3.2/tests/test_reply_where_you_are.py +66 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_session_verdict.py +1 -1
- getapo-0.3.2/tests/test_start_and_follow_up.py +155 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_task_page.py +1 -1
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_week_and_trend.py +10 -9
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_wheel.py +1 -1
- getapo-0.3.2/tests/test_work_order.py +43 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_work_tab.py +4 -3
- getapo-0.3.1/src/apo/web/templates/all_agents.html +0 -88
- getapo-0.3.1/src/apo/web/templates/all_decisions.html +0 -71
- getapo-0.3.1/src/apo/web/templates/all_work.html +0 -59
- getapo-0.3.1/src/apo/web/templates/project_agents.html +0 -42
- getapo-0.3.1/src/apo/web/templates/project_decisions.html +0 -67
- getapo-0.3.1/src/apo/web/templates/project_work.html +0 -80
- getapo-0.3.1/tests/test_decisions_tab.py +0 -59
- {getapo-0.3.1 → getapo-0.3.2}/LICENSE +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/README.md +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/THIRD_PARTY_NOTICES.md +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/pyproject.toml +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/setup.cfg +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/__main__.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/cli.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/config.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/credentials.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/installer.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/integrations/__init__.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/integrations/linear_client.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/integrations/linear_goals.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/integrations/sources.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/mcp_server.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/repo_writer.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/resources/hooks/session-decisions-nudge.sh +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/resources/skills/decisions/SKILL.md +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/transcripts.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/verify.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/__init__.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/fleet.js +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/live.js +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/notify.js +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/static/round.js +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_attachment_composer.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_icons.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_prompt_form.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/_resume_actions.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/guide.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/round.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/search.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/apo/web/templates/settings.html +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/getapo.egg-info/dependency_links.txt +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/getapo.egg-info/entry_points.txt +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/getapo.egg-info/requires.txt +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/src/getapo.egg-info/top_level.txt +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_action_spec_render.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_actions.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_answering.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_assets.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_bugs.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_bulk_and_views.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_cancel_button.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_changelog.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_checklist_back.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_claude_runtime.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_cli.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_cli_hooks.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_config.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_court.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_credentials.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_cross_site.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_dashboard_cli.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_db.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_decisions_skill.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_delivery.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_digest.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_due_stuck.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_edit_undo.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_events.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_folder_identity.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_guide.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_installer.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_item_folder.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_item_page.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_linear_client.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_live_stream.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_mcp_instructions.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_mcp_server.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_names.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_new_work.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_notes_labels.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_notify.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_now.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_now_leads.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_outcome_pages.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_outcomes.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_palette_js.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_poll_loop.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_preview_paths.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_priority_due.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_project_identity.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_project_overview.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_projects.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_prompt_answers.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_quiet_pages.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_rank_and_deps.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_repo_writer.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_resume_folder.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_round.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_scheduled_resume.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_schema.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_schema_upgrade.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_search.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_session_page.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_session_states.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_sessions.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_small_fixes.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_snooze.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_sources.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_station_read_api.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_status_export.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_sync_errors.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_task_attempts.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_task_effort.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_transcripts.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_ui_review.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_usage_limit.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_verify.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_weekly_report.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_work_items.py +0 -0
- {getapo-0.3.1 → getapo-0.3.2}/tests/test_work_location.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: getapo
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: apo (AI Project Orchestration): a local dashboard and MCP server for Claude Code. Agents ask instead of stopping; you answer every project's questions from one queue.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://getapo.pages.dev/
|
|
@@ -89,7 +89,8 @@ def work_location(path: str) -> dict | None:
|
|
|
89
89
|
"default_branch": default, "merged": merged_into(path, commit, default) if default else None}
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
# Ahead/behind counts and the
|
|
92
|
+
# Ahead/behind counts and the merge preview depend only on the two commits (for a branch
|
|
93
|
+
# with no history in common, also on the other local branches: close enough), so a page
|
|
93
94
|
# re-rendered on every database change asks git once per pair, not once per render.
|
|
94
95
|
_branch_cache: dict[tuple[str, str, str], dict] = {}
|
|
95
96
|
|
|
@@ -146,24 +147,59 @@ def merge_command(path: str, branch: str, default: str, checkout: str | None) ->
|
|
|
146
147
|
return f"git merge --no-edit {shlex.quote(branch)}, in a temporary checkout of {default}"
|
|
147
148
|
|
|
148
149
|
|
|
149
|
-
def
|
|
150
|
-
"""
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if not
|
|
154
|
-
return
|
|
155
|
-
out
|
|
150
|
+
def _merge_base(path: str, a: str, b: str) -> str | None:
|
|
151
|
+
"""The commit a and b last had in common: "" when they share no history, None when git
|
|
152
|
+
can't say."""
|
|
153
|
+
out = _git(path, "merge-base", a, b)
|
|
154
|
+
if not out or out.returncode not in (0, 1):
|
|
155
|
+
return None
|
|
156
|
+
return out.stdout.strip()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _merge_preview(path: str, default_sha: str, branch_sha: str) -> dict:
|
|
160
|
+
"""What merging the branch would do, from git's trivial three-way merge-tree: the files
|
|
161
|
+
it would likely leave conflicted, and whether it would change the default branch at
|
|
162
|
+
all (a squash-merged branch wouldn't). A hint for the list, not a promise: merge_branch
|
|
163
|
+
finds out for sure, and backs out. Anything git warns about counts as a change."""
|
|
164
|
+
base = _merge_base(path, default_sha, branch_sha)
|
|
165
|
+
if base == "":
|
|
166
|
+
return {"unrelated": True, "conflicts": [], "in_default": _in_default_files(path, default_sha, branch_sha)}
|
|
167
|
+
unknown = {"unrelated": False, "conflicts": [], "in_default": False}
|
|
168
|
+
out = _git(path, "merge-tree", base, default_sha, branch_sha) if base else None
|
|
156
169
|
if not out or out.returncode != 0:
|
|
157
|
-
return
|
|
170
|
+
return unknown
|
|
158
171
|
files: list[str] = []
|
|
159
172
|
current = None
|
|
173
|
+
modes: dict[str, str] = {}
|
|
174
|
+
changes = bool(out.stderr.strip())
|
|
160
175
|
for line in out.stdout.splitlines():
|
|
161
176
|
if line.startswith((" base ", " our ", " their ", " result ")):
|
|
162
177
|
parts = line.split(None, 3)
|
|
163
178
|
current = parts[3] if len(parts) == 4 else None
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
modes[parts[0]] = parts[1]
|
|
180
|
+
if parts[0] == "their" and parts[1] not in (modes.get("our"), modes.get("base")):
|
|
181
|
+
changes = True
|
|
182
|
+
elif line.startswith(("+", "-")):
|
|
183
|
+
changes = True
|
|
184
|
+
if line.startswith("+<<<<<<<") and current and current not in files:
|
|
185
|
+
files.append(current)
|
|
186
|
+
elif line and not line.startswith((" ", "@", "\\")):
|
|
187
|
+
changes = changes or line != "changed in both"
|
|
188
|
+
modes = {}
|
|
189
|
+
return {**unknown, "conflicts": files, "in_default": not changes}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _in_default_files(path: str, default_sha: str, branch_sha: str) -> bool:
|
|
193
|
+
"""For a branch with no history in common with the default branch: whether it's part of
|
|
194
|
+
a local branch whose files the default branch has had, as the old branches are when the
|
|
195
|
+
default branch was restarted as a fresh commit of the old history's files."""
|
|
196
|
+
trees = _git(path, "rev-list", "--format=%T", default_sha)
|
|
197
|
+
heads = _git(path, "for-each-ref", "--format=%(objectname) %(tree)", "refs/heads")
|
|
198
|
+
if not trees or trees.returncode != 0 or not heads or heads.returncode != 0:
|
|
199
|
+
return False
|
|
200
|
+
had = {line for line in trees.stdout.splitlines() if not line.startswith("commit ")}
|
|
201
|
+
return any(_is_ancestor(path, branch_sha, head) for head, _, tree in
|
|
202
|
+
(line.partition(" ") for line in heads.stdout.splitlines()) if tree in had)
|
|
167
203
|
|
|
168
204
|
|
|
169
205
|
def _pair_state(path: str, default_sha: str, branch_sha: str) -> dict | None:
|
|
@@ -175,17 +211,23 @@ def _pair_state(path: str, default_sha: str, branch_sha: str) -> dict | None:
|
|
|
175
211
|
behind, ahead = (int(n) for n in out.stdout.split())
|
|
176
212
|
if len(_branch_cache) > 500:
|
|
177
213
|
_branch_cache.clear()
|
|
178
|
-
|
|
179
|
-
|
|
214
|
+
preview = {"unrelated": False, "conflicts": [], "in_default": not ahead}
|
|
215
|
+
# Not behind is a fast-forward: nothing can have reached the default branch another way.
|
|
216
|
+
if ahead and behind:
|
|
217
|
+
preview = _merge_preview(path, default_sha, branch_sha)
|
|
218
|
+
_branch_cache[key] = {"ahead": ahead, "behind": behind, **preview}
|
|
180
219
|
state = _branch_cache[key]
|
|
181
220
|
return {**state, "conflicts": list(state["conflicts"])}
|
|
182
221
|
|
|
183
222
|
|
|
184
223
|
def mergeable_branches(path: str) -> dict:
|
|
185
|
-
"""Local branches with
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
224
|
+
"""Local branches with work the default branch doesn't have, newest first: what agents
|
|
225
|
+
finished in worktrees and nobody has merged yet. Work that reached the default branch
|
|
226
|
+
another way (squash-merged, or the default branch restarted from its files) isn't
|
|
227
|
+
listed; a branch with no history in common is, marked unrelated, since git won't merge
|
|
228
|
+
it. checkout is where the default branch is checked out (the merge happens there),
|
|
229
|
+
blocked why it can't happen now, main_checkout the repository's own folder as opposed
|
|
230
|
+
to its added worktrees."""
|
|
189
231
|
listing = {"default_branch": None, "checkout": None, "main_checkout": None, "blocked": None, "branches": []}
|
|
190
232
|
default = default_branch(path)
|
|
191
233
|
default_sha = _sha(path, f"refs/heads/{default}") if default else None
|
|
@@ -207,14 +249,14 @@ def mergeable_branches(path: str) -> dict:
|
|
|
207
249
|
ref, sha, at, subject = parts
|
|
208
250
|
name = ref[len("refs/heads/"):]
|
|
209
251
|
state = _pair_state(path, default_sha, sha)
|
|
210
|
-
if name == default or not state or
|
|
252
|
+
if name == default or not state or state["in_default"]:
|
|
211
253
|
continue
|
|
212
254
|
listing["branches"].append({
|
|
213
255
|
"branch": name, "commit": sha, "subject": subject,
|
|
214
256
|
"at": datetime.fromisoformat(at).astimezone(timezone.utc).isoformat(),
|
|
215
257
|
"worktree": checked_out.get(name), "command": merge_command(path, name, default, checkout), **state,
|
|
216
258
|
})
|
|
217
|
-
if listing["branches"]:
|
|
259
|
+
if any(not b["unrelated"] for b in listing["branches"]):
|
|
218
260
|
listing["blocked"] = _blocked(default, checkout)
|
|
219
261
|
return listing
|
|
220
262
|
|
|
@@ -231,9 +273,10 @@ def branch_state(path: str, branch: str) -> dict | None:
|
|
|
231
273
|
if state is None:
|
|
232
274
|
return None
|
|
233
275
|
checkout = _checkout_of(path, default)
|
|
234
|
-
|
|
276
|
+
mergeable = not state["in_default"] and not state["unrelated"]
|
|
277
|
+
return {"branch": branch, "commit": branch_sha, "default_branch": default, "merged": state["in_default"],
|
|
235
278
|
"checkout": checkout,
|
|
236
|
-
"blocked": _blocked(default, checkout) if
|
|
279
|
+
"blocked": _blocked(default, checkout) if mergeable else None,
|
|
237
280
|
"command": merge_command(path, branch, default, checkout), **state}
|
|
238
281
|
|
|
239
282
|
|
|
@@ -271,7 +314,8 @@ def merge_branch(path: str, branch: str) -> dict:
|
|
|
271
314
|
in the checkout that has the default branch, which must have no uncommitted changes
|
|
272
315
|
to tracked files. With the default branch checked out nowhere, a fast-forward just
|
|
273
316
|
moves it, and anything else merges in a temporary checkout removed afterwards. A
|
|
274
|
-
conflict is backed out, leaving everything as it was.
|
|
317
|
+
conflict is backed out, leaving everything as it was. A branch with no history in
|
|
318
|
+
common is refused: forcing it would bring that whole history into the default branch."""
|
|
275
319
|
result = {"ok": False, "error": None, "branch": branch, "into": None, "checkout": None, "commit": None,
|
|
276
320
|
"fast_forward": False, "already": False, "conflicts": []}
|
|
277
321
|
default = default_branch(path)
|
|
@@ -284,6 +328,9 @@ def merge_branch(path: str, branch: str) -> dict:
|
|
|
284
328
|
return {**result, "error": f"There's no other local branch named {branch!r} to merge into {default}."}
|
|
285
329
|
if _is_ancestor(path, branch_sha, default_sha):
|
|
286
330
|
return {**result, "ok": True, "already": True, "commit": default_sha}
|
|
331
|
+
if _merge_base(path, default_sha, branch_sha) == "":
|
|
332
|
+
return {**result, "error": f"{branch} has no history in common with {default}, so apo won't merge it. "
|
|
333
|
+
f"Nothing was changed."}
|
|
287
334
|
checkout = _checkout_of(path, default)
|
|
288
335
|
if checkout:
|
|
289
336
|
blocked = _blocked(default, checkout)
|
|
@@ -309,6 +356,31 @@ def merge_branch(path: str, branch: str) -> dict:
|
|
|
309
356
|
_git(path, "worktree", "prune")
|
|
310
357
|
|
|
311
358
|
|
|
359
|
+
def clean_up_branch(path: str, branch: str) -> dict:
|
|
360
|
+
"""After a merge: remove the added worktree the branch is checked out in, then delete
|
|
361
|
+
the branch, with git's own safety: a worktree with changes or untracked files stays,
|
|
362
|
+
and so does a branch git doesn't count as merged. The repository's own folder is never
|
|
363
|
+
removed."""
|
|
364
|
+
result = {"worktree": None, "worktree_removed": False, "branch_deleted": False, "error": None}
|
|
365
|
+
trees = worktrees(path)
|
|
366
|
+
main = trees[0]["path"] if trees else None
|
|
367
|
+
where = next((w["path"] for w in trees if w["branch"] == branch), None)
|
|
368
|
+
if where and where == main:
|
|
369
|
+
return {**result, "error": f"{branch} is checked out in the repository's own folder, so it was kept."}
|
|
370
|
+
if where:
|
|
371
|
+
result["worktree"] = where
|
|
372
|
+
out = _git(path, "worktree", "remove", where)
|
|
373
|
+
if not out or out.returncode != 0:
|
|
374
|
+
reason = (out.stderr.strip() if out else "") or "git failed"
|
|
375
|
+
return {**result, "error": f"Kept the worktree {_home(where)}: {reason}"}
|
|
376
|
+
result["worktree_removed"] = True
|
|
377
|
+
out = _git(path, "branch", "-d", branch)
|
|
378
|
+
if not out or out.returncode != 0:
|
|
379
|
+
reason = (out.stderr.strip() if out else "") or "git failed"
|
|
380
|
+
return {**result, "error": f"Kept the branch {branch}: {reason}"}
|
|
381
|
+
return {**result, "branch_deleted": True}
|
|
382
|
+
|
|
383
|
+
|
|
312
384
|
def has_pull_requests_cache(path: str) -> bool:
|
|
313
385
|
return os.path.realpath(path) in _pr_cache
|
|
314
386
|
|
|
@@ -14,7 +14,7 @@ import re
|
|
|
14
14
|
import subprocess
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
|
|
17
|
-
from apo import config
|
|
17
|
+
from apo import config, transcripts
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class LaunchError(RuntimeError):
|
|
@@ -44,6 +44,30 @@ def claude_config_dirs() -> list[Path]:
|
|
|
44
44
|
return dirs
|
|
45
45
|
|
|
46
46
|
|
|
47
|
+
def _env_for(profile: Path | None) -> dict | None:
|
|
48
|
+
"""The environment a claude command acting in `profile` runs with. This process's
|
|
49
|
+
own profile (or an unknown one) leaves it untouched; the default ~/.claude is
|
|
50
|
+
reached by unsetting CLAUDE_CONFIG_DIR, since pointing it at ~/.claude also moves
|
|
51
|
+
~/.claude.json."""
|
|
52
|
+
if profile is None or profile == claude_config_dir():
|
|
53
|
+
return None
|
|
54
|
+
env = dict(os.environ)
|
|
55
|
+
if profile == Path.home() / ".claude":
|
|
56
|
+
env.pop("CLAUDE_CONFIG_DIR", None)
|
|
57
|
+
else:
|
|
58
|
+
env["CLAUDE_CONFIG_DIR"] = str(profile)
|
|
59
|
+
return env
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def session_profile(session_id: str) -> Path | None:
|
|
63
|
+
"""The profile a session belongs to: the one keeping its transcript. `--resume` and
|
|
64
|
+
`claude stop` only find a session from inside its own profile."""
|
|
65
|
+
for folder in claude_config_dirs():
|
|
66
|
+
if transcripts.find(session_id, [folder]):
|
|
67
|
+
return folder
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
|
|
47
71
|
def subagent_for_worktree(worktree: str) -> dict | None:
|
|
48
72
|
"""The subagent Claude Code made a worktree for, from the meta file it keeps beside
|
|
49
73
|
the subagent's transcript, <profile>/projects/<slug>/<parent session>/subagents/
|
|
@@ -95,11 +119,8 @@ def list_agents(timeout: float = 5.0) -> list[dict] | None:
|
|
|
95
119
|
claude_config_dirs(), and is None if any one of them can't be listed: half a
|
|
96
120
|
picture would end every live session of the profile that failed."""
|
|
97
121
|
merged: list[dict] = []
|
|
98
|
-
for
|
|
99
|
-
|
|
100
|
-
# CLAUDE_CONFIG_DIR to the default ~/.claude also moves ~/.claude.json.
|
|
101
|
-
env = None if index == 0 else {**os.environ, "CLAUDE_CONFIG_DIR": str(folder)}
|
|
102
|
-
agents = _list_agents_in(env, timeout)
|
|
122
|
+
for folder in claude_config_dirs():
|
|
123
|
+
agents = _list_agents_in(_env_for(folder), timeout)
|
|
103
124
|
if agents is None:
|
|
104
125
|
return None
|
|
105
126
|
merged.extend(agents)
|
|
@@ -140,9 +161,11 @@ def current_session_id(pid: int | None = None) -> str | None:
|
|
|
140
161
|
_SAFE_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9_-]{0,127}")
|
|
141
162
|
|
|
142
163
|
|
|
143
|
-
def _run(args: list[str], cwd: str | None, timeout: float, input: str | None = None
|
|
164
|
+
def _run(args: list[str], cwd: str | None, timeout: float, input: str | None = None,
|
|
165
|
+
profile: Path | None = None) -> str:
|
|
144
166
|
try:
|
|
145
167
|
result = subprocess.run([_binary(), *args], cwd=cwd, capture_output=True, text=True, timeout=timeout,
|
|
168
|
+
env=_env_for(profile),
|
|
146
169
|
**({"input": input} if input is not None else {"stdin": subprocess.DEVNULL}))
|
|
147
170
|
except (OSError, subprocess.SubprocessError) as exc:
|
|
148
171
|
raise LaunchError(f"Couldn't run claude: {exc}") from exc
|
|
@@ -157,11 +180,11 @@ PERMISSION_MODES = ("acceptEdits", "plan")
|
|
|
157
180
|
|
|
158
181
|
|
|
159
182
|
def start_background(cwd: str, prompt: str, resume: str | None = None, timeout: float = 30.0,
|
|
160
|
-
permission_mode: str | None = None) -> str | None:
|
|
183
|
+
permission_mode: str | None = None, profile: Path | None = None) -> str | None:
|
|
161
184
|
"""`claude --bg` returns as soon as the session is up and prints the short id
|
|
162
185
|
that `claude agents`, `stop` and `attach` take. Permission prompts in that
|
|
163
186
|
session still surface in Claude Code's own agent view — nothing here approves
|
|
164
|
-
anything on the agent's behalf."""
|
|
187
|
+
anything on the agent's behalf. It runs in `profile`, this process's own if None."""
|
|
165
188
|
if prompt.lstrip().startswith("-"):
|
|
166
189
|
raise LaunchError("A prompt can't start with '-' (claude would read it as an option).")
|
|
167
190
|
if resume is not None and not _SAFE_ID.fullmatch(resume):
|
|
@@ -170,16 +193,25 @@ def start_background(cwd: str, prompt: str, resume: str | None = None, timeout:
|
|
|
170
193
|
raise LaunchError(f"Not an allowed permission mode: {permission_mode!r}")
|
|
171
194
|
args = ["--bg", *(["--permission-mode", permission_mode] if permission_mode else []),
|
|
172
195
|
*(["--resume", resume] if resume else []), prompt]
|
|
173
|
-
output = _run(args, cwd, timeout)
|
|
196
|
+
output = _run(args, cwd, timeout, profile=profile)
|
|
174
197
|
match = re.search(r"\b[0-9a-f]{8}\b", output)
|
|
175
198
|
return match.group(0) if match else None
|
|
176
199
|
|
|
177
200
|
|
|
178
|
-
def stop_background(agent_id: str, timeout: float = 15.0) -> bool:
|
|
201
|
+
def stop_background(agent_id: str, timeout: float = 15.0, profile: Path | None = None) -> bool:
|
|
202
|
+
"""`claude stop` only reaches a session from inside its own profile: `profile` is
|
|
203
|
+
tried first, then every other one apo knows about. The first failure is the one
|
|
204
|
+
reported."""
|
|
179
205
|
if not _SAFE_ID.fullmatch(agent_id):
|
|
180
206
|
raise LaunchError(f"Not a background session id: {agent_id!r}")
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
error = None
|
|
208
|
+
for folder in [*([profile] if profile else []), *(d for d in claude_config_dirs() if d != profile)]:
|
|
209
|
+
try:
|
|
210
|
+
_run(["stop", agent_id], None, timeout, profile=folder)
|
|
211
|
+
return True
|
|
212
|
+
except LaunchError as exc:
|
|
213
|
+
error = error or exc
|
|
214
|
+
raise error
|
|
183
215
|
|
|
184
216
|
|
|
185
217
|
RECAP_PROMPT = (
|
|
@@ -864,7 +864,7 @@ def _search_hit(conn: sqlite3.Connection, kind: str, rowid: int, terms: list[str
|
|
|
864
864
|
s = dict(row)
|
|
865
865
|
s["project_name"] = get_project_name(conn, s["project_id"]) if s["project_id"] else None
|
|
866
866
|
hit = {"title": _session_name(s), "status": s["status"], "subkind": "session",
|
|
867
|
-
"href": f"/sessions
|
|
867
|
+
"href": f"/sessions/{s['id']}", "resume_command": session_resume_command(s)}
|
|
868
868
|
else:
|
|
869
869
|
row = conn.execute("SELECT id, title, status, project_id FROM outcomes WHERE id = ?", (rowid,)).fetchone()
|
|
870
870
|
if row is None:
|
|
@@ -888,6 +888,17 @@ def _item_filter(label: str, owner: str, status: str):
|
|
|
888
888
|
|
|
889
889
|
def search(conn: sqlite3.Connection, query: str, limit: int = 50, label: str = "", owner: str = "",
|
|
890
890
|
status: str = "") -> list[dict]:
|
|
891
|
+
"""_search_text, with an item named by its number or a session by its id first."""
|
|
892
|
+
keep = _item_filter(label, owner, status)
|
|
893
|
+
by_id = [h for h in _id_hits(conn, query) if h["kind"] != "item" or keep(h)]
|
|
894
|
+
if by_id and (query or "").strip().startswith("#"):
|
|
895
|
+
return by_id
|
|
896
|
+
found = {(h["kind"], h["ref"]) for h in by_id}
|
|
897
|
+
return by_id + [h for h in _search_text(conn, query, limit, label, owner, status) if (h["kind"], h["ref"]) not in found]
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
def _search_text(conn: sqlite3.Connection, query: str, limit: int = 50, label: str = "", owner: str = "",
|
|
901
|
+
status: str = "") -> list[dict]:
|
|
891
902
|
"""Every word has to match, anywhere in the title or text. Words of 3+
|
|
892
903
|
characters go through the trigram index; shorter ones (which trigrams can't
|
|
893
904
|
express) filter what that returns, or fall back to LIKE when they're all short."""
|
|
@@ -928,6 +939,20 @@ def search(conn: sqlite3.Connection, query: str, limit: int = 50, label: str = "
|
|
|
928
939
|
return hits
|
|
929
940
|
|
|
930
941
|
|
|
942
|
+
def _id_hits(conn: sqlite3.Connection, query: str) -> list[dict]:
|
|
943
|
+
"""An item by its number (#447 or 447), or sessions by the start of their id or their
|
|
944
|
+
background agent id, whatever their status: what you have when you come from a terminal."""
|
|
945
|
+
text = (query or "").strip()
|
|
946
|
+
if re.fullmatch(r"#?\d+", text):
|
|
947
|
+
hit = _search_hit(conn, "item", int(text.lstrip("#")), [], "")
|
|
948
|
+
return [hit] if hit else []
|
|
949
|
+
if re.fullmatch(r"[0-9A-Za-z][\w-]{5,}", text):
|
|
950
|
+
rows = conn.execute("SELECT id FROM sessions WHERE claude_session_id LIKE ? OR agent_id LIKE ? "
|
|
951
|
+
"ORDER BY last_seen_at DESC LIMIT 10", (text + "%", text + "%")).fetchall()
|
|
952
|
+
return [h for h in (_search_hit(conn, "session", r["id"], [], "") for r in rows) if h]
|
|
953
|
+
return []
|
|
954
|
+
|
|
955
|
+
|
|
931
956
|
def _filter_date(value: str | None) -> str | None:
|
|
932
957
|
if not value:
|
|
933
958
|
return None
|
|
@@ -1027,7 +1052,7 @@ def search_transcripts(conn: sqlite3.Connection, query: str, timeout: float = 10
|
|
|
1027
1052
|
clean = excerpt.replace("\\n", " ").replace('\\"', '"')
|
|
1028
1053
|
hits.append({"kind": "transcript", "ref": sid, "title": _session_name(s), "status": s["status"],
|
|
1029
1054
|
"subkind": "transcript", "project_name": s["project_name"], "snippet": _snippet(clean, [query]),
|
|
1030
|
-
"href": f"/sessions
|
|
1055
|
+
"href": f"/sessions/{s['id']}", "resume_command": session_resume_command(s),
|
|
1031
1056
|
"last_seen_at": s["last_seen_at"]})
|
|
1032
1057
|
hits.sort(key=lambda h: h["last_seen_at"] or "", reverse=True)
|
|
1033
1058
|
return hits[:limit]
|
|
@@ -1214,6 +1239,26 @@ def permission_mode_for_path(conn: sqlite3.Connection, path: str) -> str | None:
|
|
|
1214
1239
|
return AUTONOMY_MODES[project_autonomy(conn, repository["project_id"])] if repository else None
|
|
1215
1240
|
|
|
1216
1241
|
|
|
1242
|
+
def claude_profile_for_path(conn: sqlite3.Connection, path: str) -> Path | None:
|
|
1243
|
+
"""The Claude Code profile a background session started in `path` runs under: the
|
|
1244
|
+
one keeping the transcript of its project's latest session. A session started in a
|
|
1245
|
+
terminal ran with the folder's own environment, so it counts before a background
|
|
1246
|
+
one, which may have been started from anywhere."""
|
|
1247
|
+
from apo import claude_runtime
|
|
1248
|
+
|
|
1249
|
+
repository = find_repository_by_path(conn, path)
|
|
1250
|
+
if repository is None:
|
|
1251
|
+
return None
|
|
1252
|
+
for row in conn.execute(
|
|
1253
|
+
"SELECT claude_session_id FROM sessions WHERE project_id = ? "
|
|
1254
|
+
"ORDER BY agent_kind IS 'background', last_seen_at DESC LIMIT 20", (repository["project_id"],),
|
|
1255
|
+
).fetchall():
|
|
1256
|
+
profile = claude_runtime.session_profile(row["claude_session_id"])
|
|
1257
|
+
if profile:
|
|
1258
|
+
return profile
|
|
1259
|
+
return None
|
|
1260
|
+
|
|
1261
|
+
|
|
1217
1262
|
def list_standing_rules(conn: sqlite3.Connection, project_id: int) -> list[dict]:
|
|
1218
1263
|
return [dict(r) for r in conn.execute(
|
|
1219
1264
|
"SELECT * FROM standing_rules WHERE project_id = ? AND retired_at IS NULL ORDER BY id", (project_id,))]
|
|
@@ -1539,7 +1584,8 @@ def project_work(conn: sqlite3.Connection, project_id: int | None) -> dict:
|
|
|
1539
1584
|
owner = _OWNER_WORDS.get(d.get("assignee") or "human", "you")
|
|
1540
1585
|
item = {"id": d["id"], "kind": d["kind"], "title": d["title"], "owner": owner, "labels": d.get("labels") or [],
|
|
1541
1586
|
"note_count": d.get("note_count") or 0, "since": d["created_at"], "href": f"/decisions/{d['id']}", "summary": d.get("summary"),
|
|
1542
|
-
"project_id": d["project_id"], "project_name": row["project_name"], "due_on": d.get("due_on")
|
|
1587
|
+
"project_id": d["project_id"], "project_name": row["project_name"], "due_on": d.get("due_on"),
|
|
1588
|
+
"recommendation": d.get("recommendation")}
|
|
1543
1589
|
status = d["status"]
|
|
1544
1590
|
item["due_bucket"] = None if status in ("resolved", "cancelled") else due_bucket(d.get("due_on"))
|
|
1545
1591
|
item["stuck"] = None
|
|
@@ -1554,7 +1600,10 @@ def project_work(conn: sqlite3.Connection, project_id: int | None) -> dict:
|
|
|
1554
1600
|
"since": d.get("answered_at")})
|
|
1555
1601
|
elif status == "in_progress":
|
|
1556
1602
|
since = d.get("claimed_at") or d["created_at"]
|
|
1603
|
+
session = conn.execute("SELECT id FROM sessions WHERE claude_session_id = ?",
|
|
1604
|
+
(d.get("claimed_by_session_id"),)).fetchone()
|
|
1557
1605
|
groups["in_progress"].append({**item, "state": "Claimed", "since": since,
|
|
1606
|
+
"session_id": session["id"] if session else None,
|
|
1558
1607
|
"stuck": stuck_info(since, "claimed with no activity")})
|
|
1559
1608
|
elif open_blockers(conn, d["id"]):
|
|
1560
1609
|
groups["waiting"].append({**item, "state": "Waits on " + ", ".join(f"#{b}" for b in open_blockers(conn, d["id"]))})
|
|
@@ -1563,7 +1612,9 @@ def project_work(conn: sqlite3.Connection, project_id: int | None) -> dict:
|
|
|
1563
1612
|
target = "needs_you" if due else "waiting"
|
|
1564
1613
|
groups[target].append({**item, "state": "Check on it" if due else f"Waiting on {d.get('waiting_on') or 'someone else'}"})
|
|
1565
1614
|
elif owner == "agent":
|
|
1566
|
-
|
|
1615
|
+
dispatched = dispatched_session(conn, d) if d.get("dispatch_agent_id") else None
|
|
1616
|
+
groups["ready"].append({**item, "state": "Ready", "dispatched": dispatch_in_flight(conn, d),
|
|
1617
|
+
"session_id": dispatched["id"] if dispatched else None, "stuck": stuck_info(
|
|
1567
1618
|
d["created_at"], "ready, but no agent has picked it up")})
|
|
1568
1619
|
else:
|
|
1569
1620
|
state = {"decision": "Decide", "action": "Do it", "review": "Review"}.get(d["kind"], "Yours")
|
|
@@ -2153,9 +2204,23 @@ def complete_task(
|
|
|
2153
2204
|
_item_event(conn, task_id, "item.completed", "Done" if outcome != "partial" else "Partly done",
|
|
2154
2205
|
actor=by, detail=note)
|
|
2155
2206
|
_sync_repo_files(conn, task_id)
|
|
2207
|
+
if completion.get("left_for_human"):
|
|
2208
|
+
_leave_for_human(conn, task_id, completion["left_for_human"])
|
|
2156
2209
|
return bool(cur.rowcount)
|
|
2157
2210
|
|
|
2158
2211
|
|
|
2212
|
+
def _leave_for_human(conn: sqlite3.Connection, task_id: int, text: str) -> int:
|
|
2213
|
+
"""What a finished task left for you, as an action on your Now: as text on the task
|
|
2214
|
+
alone, nothing would ever bring it back to you."""
|
|
2215
|
+
task = get_decision_request(conn, task_id)
|
|
2216
|
+
first = next((line.strip() for line in text.splitlines() if line.strip()), text.strip())
|
|
2217
|
+
return create_decision_request(
|
|
2218
|
+
conn, project_id=task["project_id"], repository_id=task["repository_id"], kind="action",
|
|
2219
|
+
title=f"Left for you by #{task_id}: {first[:80]}", question=f"{text}\n\nFrom #{task_id} {task['title']}.",
|
|
2220
|
+
requested_by="agent", outcome_id=task.get("outcome_id"),
|
|
2221
|
+
)
|
|
2222
|
+
|
|
2223
|
+
|
|
2159
2224
|
def retry_task(conn: sqlite3.Connection, task_id: int, note: str | None = None, by: str = "human") -> bool:
|
|
2160
2225
|
"""Put a task that failed, was abandoned, was cancelled, or is held by a session that
|
|
2161
2226
|
will never finish it back to READY. The claim is released and the finish cleared from
|
|
@@ -3775,7 +3840,7 @@ def merge_projects(conn: sqlite3.Connection, from_project_id: int, into_project_
|
|
|
3775
3840
|
sessions = conn.execute(
|
|
3776
3841
|
"UPDATE sessions SET project_id = ? WHERE project_id = ?", (into_project_id, from_project_id)
|
|
3777
3842
|
).rowcount
|
|
3778
|
-
for table in ("project_aliases", "outcomes", "events"):
|
|
3843
|
+
for table in ("project_aliases", "outcomes", "standing_rules", "notifications", "events"):
|
|
3779
3844
|
conn.execute(f"UPDATE {table} SET project_id = ? WHERE project_id = ?", (into_project_id, from_project_id))
|
|
3780
3845
|
conn.execute("DELETE FROM projects WHERE id = ?", (from_project_id,))
|
|
3781
3846
|
conn.commit()
|
|
@@ -4191,6 +4256,17 @@ def _session_name(s: dict) -> str:
|
|
|
4191
4256
|
return s.get("project_name") or os.path.basename((s.get("cwd") or "").rstrip("/")) or s["claude_session_id"][:8]
|
|
4192
4257
|
|
|
4193
4258
|
|
|
4259
|
+
def now_next_item(conn: sqlite3.Connection, decision_id: int) -> dict | None:
|
|
4260
|
+
"""The request after this one among those Now asks you about, in Now's order: where
|
|
4261
|
+
answering an item opened from Now goes next. None after the last."""
|
|
4262
|
+
lanes = now_queue(conn)
|
|
4263
|
+
ids = list(dict.fromkeys(i["decision"]["id"] for lane in ("problems", "your_move", "asks")
|
|
4264
|
+
for i in lanes[lane] if i.get("decision")))
|
|
4265
|
+
rest = ids[ids.index(decision_id) + 1:] if decision_id in ids else ids
|
|
4266
|
+
nxt = next((i for i in rest if i != decision_id), None)
|
|
4267
|
+
return {"id": nxt, "title": get_decision_request(conn, nxt)["title"]} if nxt else None
|
|
4268
|
+
|
|
4269
|
+
|
|
4194
4270
|
def now_queue(conn: sqlite3.Connection, project_id: int | None = None) -> dict:
|
|
4195
4271
|
"""Lanes, each a list of items {key, kind, project_name, title, reason, since,
|
|
4196
4272
|
effort, score, ...}: problems (faults only the human can recover), your_move
|
|
@@ -4380,6 +4456,15 @@ def time_boxed_plan(queue: dict, minutes: float | None) -> list[dict]:
|
|
|
4380
4456
|
|
|
4381
4457
|
|
|
4382
4458
|
BULK_ACCEPT_MIN_CONFIDENCE = 85
|
|
4459
|
+
# Accept in bulk can be loosened on its page, never below this.
|
|
4460
|
+
BULK_ACCEPT_FLOOR = 50
|
|
4461
|
+
|
|
4462
|
+
|
|
4463
|
+
def bulk_accept_threshold(value) -> int:
|
|
4464
|
+
try:
|
|
4465
|
+
return max(BULK_ACCEPT_FLOOR, min(100, int(value)))
|
|
4466
|
+
except (TypeError, ValueError):
|
|
4467
|
+
return BULK_ACCEPT_MIN_CONFIDENCE
|
|
4383
4468
|
|
|
4384
4469
|
|
|
4385
4470
|
def bulk_accept_candidates(conn: sqlite3.Connection, project_id: int | None = None,
|
|
@@ -4412,9 +4497,10 @@ def bulk_accept_candidates(conn: sqlite3.Connection, project_id: int | None = No
|
|
|
4412
4497
|
return candidates
|
|
4413
4498
|
|
|
4414
4499
|
|
|
4415
|
-
def bulk_accept(conn: sqlite3.Connection, ids: Iterable[int]
|
|
4500
|
+
def bulk_accept(conn: sqlite3.Connection, ids: Iterable[int],
|
|
4501
|
+
min_confidence: int = BULK_ACCEPT_MIN_CONFIDENCE) -> list[int]:
|
|
4416
4502
|
"""Eligibility is checked again here, not trusted from the form."""
|
|
4417
|
-
eligible = {d["id"]: d for d in bulk_accept_candidates(conn)}
|
|
4503
|
+
eligible = {d["id"]: d for d in bulk_accept_candidates(conn, min_confidence=bulk_accept_threshold(min_confidence))}
|
|
4418
4504
|
accepted = []
|
|
4419
4505
|
for decision_id in ids:
|
|
4420
4506
|
d = eligible.get(decision_id)
|
|
@@ -4902,6 +4988,72 @@ def court_metrics(conn: sqlite3.Connection, now: datetime | None = None) -> dict
|
|
|
4902
4988
|
}
|
|
4903
4989
|
|
|
4904
4990
|
|
|
4991
|
+
def session_terminal_command(s: dict) -> str:
|
|
4992
|
+
"""What opens a session in a terminal. A background session that's still running is
|
|
4993
|
+
attached to: resuming it would start a second process on the same conversation."""
|
|
4994
|
+
import shlex
|
|
4995
|
+
|
|
4996
|
+
if s.get("status") != "ended" and s.get("agent_kind") == "background" and s.get("agent_id"):
|
|
4997
|
+
return f"claude attach {shlex.quote(s['agent_id'])}"
|
|
4998
|
+
return session_resume_command(s) or f"claude --resume {shlex.quote(s['claude_session_id'])}"
|
|
4999
|
+
|
|
5000
|
+
|
|
5001
|
+
def items_for_sessions(conn: sqlite3.Connection, sessions: list[dict]) -> dict[str, dict]:
|
|
5002
|
+
"""The task each session works on (claimed, or was started on in the background), by
|
|
5003
|
+
claude session id; the latest one when there were several."""
|
|
5004
|
+
claude_ids = [s["claude_session_id"] for s in sessions]
|
|
5005
|
+
by_agent = {s["agent_id"]: s["claude_session_id"] for s in sessions if s.get("agent_id")}
|
|
5006
|
+
if not claude_ids:
|
|
5007
|
+
return {}
|
|
5008
|
+
marks = ", ".join("?" * len(claude_ids))
|
|
5009
|
+
agent_marks = ", ".join("?" * len(by_agent)) or "NULL"
|
|
5010
|
+
found: dict[str, dict] = {}
|
|
5011
|
+
for row in conn.execute(
|
|
5012
|
+
"SELECT id, title, status, claimed_by_session_id, dispatch_agent_id FROM decision_requests "
|
|
5013
|
+
f"WHERE claimed_by_session_id IN ({marks}) OR dispatch_agent_id IN ({agent_marks}) "
|
|
5014
|
+
"ORDER BY COALESCE(claimed_at, dispatched_at, created_at)", (*claude_ids, *by_agent)):
|
|
5015
|
+
owner = row["claimed_by_session_id"] if row["claimed_by_session_id"] in claude_ids else by_agent.get(row["dispatch_agent_id"])
|
|
5016
|
+
if owner:
|
|
5017
|
+
found[owner] = {"id": row["id"], "title": row["title"], "status": row["status"]}
|
|
5018
|
+
return found
|
|
5019
|
+
|
|
5020
|
+
|
|
5021
|
+
def item_connections(conn: sqlite3.Connection, item: dict) -> dict:
|
|
5022
|
+
"""What an item's page links to: its goal, the session that filed it, and the sessions
|
|
5023
|
+
that worked on it (claimed it, were started on it, or were handed its answer), as
|
|
5024
|
+
claude session ids."""
|
|
5025
|
+
goal = None
|
|
5026
|
+
if item.get("outcome_id"):
|
|
5027
|
+
row = conn.execute("SELECT id, title, status FROM outcomes WHERE id = ?", (item["outcome_id"],)).fetchone()
|
|
5028
|
+
goal = dict(row) if row else None
|
|
5029
|
+
dispatched = dispatched_session(conn, item)
|
|
5030
|
+
filed_by = item.get("origin_session_id")
|
|
5031
|
+
workers = [item.get("claimed_by_session_id"), dispatched["claude_session_id"] if dispatched else None,
|
|
5032
|
+
item.get("delivered_to_session")]
|
|
5033
|
+
return {"goal": goal, "filed_by": filed_by,
|
|
5034
|
+
"workers": [w for w in dict.fromkeys(workers) if w and w != filed_by]}
|
|
5035
|
+
|
|
5036
|
+
|
|
5037
|
+
def session_connections(conn: sqlite3.Connection, session: dict) -> dict:
|
|
5038
|
+
"""What a session's page links to: the items it worked on (claimed, was started on, or
|
|
5039
|
+
was handed the answer to), the requests it filed, open ones first, and their goals."""
|
|
5040
|
+
claude_id = session["claude_session_id"]
|
|
5041
|
+
fields = "id, title, kind, status, outcome_id"
|
|
5042
|
+
asked = [dict(r) for r in conn.execute(
|
|
5043
|
+
f"SELECT {fields} FROM decision_requests WHERE origin_session_id = ? "
|
|
5044
|
+
"ORDER BY status != 'open', id DESC LIMIT 20", (claude_id,))]
|
|
5045
|
+
asked_ids = {i["id"] for i in asked}
|
|
5046
|
+
working = [dict(r) for r in conn.execute(
|
|
5047
|
+
f"SELECT {fields} FROM decision_requests WHERE claimed_by_session_id = ? OR delivered_to_session = ? "
|
|
5048
|
+
"OR (dispatch_agent_id IS NOT NULL AND dispatch_agent_id = ?) ORDER BY id DESC LIMIT 20",
|
|
5049
|
+
(claude_id, claude_id, session.get("agent_id"))) if r["id"] not in asked_ids]
|
|
5050
|
+
goal_ids = [g for g in dict.fromkeys([session.get("outcome_id"), *(i["outcome_id"] for i in working + asked)]) if g]
|
|
5051
|
+
goals = [dict(r) for r in conn.execute(
|
|
5052
|
+
f"SELECT id, title, status FROM outcomes WHERE id IN ({', '.join('?' * len(goal_ids))})", goal_ids)] \
|
|
5053
|
+
if goal_ids else []
|
|
5054
|
+
return {"working": working, "asked": asked, "goals": goals}
|
|
5055
|
+
|
|
5056
|
+
|
|
4905
5057
|
def session_resume_command(s: dict) -> str | None:
|
|
4906
5058
|
import shlex
|
|
4907
5059
|
|
|
@@ -5629,6 +5781,7 @@ def record_session_summary(
|
|
|
5629
5781
|
|
|
5630
5782
|
def list_sessions(
|
|
5631
5783
|
conn: sqlite3.Connection, include_ended: bool = False, ended_since: str | None = None,
|
|
5784
|
+
claude_session_ids: Iterable[str] | None = None,
|
|
5632
5785
|
) -> list[dict]:
|
|
5633
5786
|
"""Enriched rows for the fleet view / /api/sessions, derived here — the one place
|
|
5634
5787
|
— so nothing else duplicates the logic:
|
|
@@ -5659,7 +5812,12 @@ def list_sessions(
|
|
|
5659
5812
|
LEFT JOIN decision_requests ON decision_requests.id = open_requests.first_id
|
|
5660
5813
|
"""
|
|
5661
5814
|
params: list = []
|
|
5662
|
-
if
|
|
5815
|
+
if claude_session_ids is not None:
|
|
5816
|
+
params = list(dict.fromkeys(claude_session_ids))
|
|
5817
|
+
if not params:
|
|
5818
|
+
return []
|
|
5819
|
+
query += f" WHERE sessions.claude_session_id IN ({', '.join('?' * len(params))})"
|
|
5820
|
+
elif ended_since is not None:
|
|
5663
5821
|
query += " WHERE sessions.status != 'ended' OR sessions.last_seen_at >= ?"
|
|
5664
5822
|
params.append(ended_since)
|
|
5665
5823
|
elif not include_ended:
|