getapo 0.3.0__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.0/src/getapo.egg-info → getapo-0.3.2}/PKG-INFO +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/__init__.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/changelog.py +95 -23
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/claude_runtime.py +45 -13
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/db.py +253 -20
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/resources/guide.md +37 -33
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/app.py +309 -155
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/app.css +51 -3
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/app.js +38 -24
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/now.js +2 -2
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/_attachment_composer.html +1 -2
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/_macros.html +6 -0
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/_now_item.html +24 -2
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/_session_card.html +6 -1
- getapo-0.3.0/src/apo/web/templates/week.html → getapo-0.3.2/src/apo/web/templates/_week_overview.html +9 -29
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_work_location.html +4 -2
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_work_main.html +15 -2
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_work_status.html +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/accept.html +5 -0
- {getapo-0.3.0 → 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.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/base.html +9 -4
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/decision.html +32 -6
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/now.html +29 -1
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/outcome.html +63 -41
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/project_overview.html +13 -33
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/src/apo/web/templates/projects_shell.html +2 -2
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/report.html +1 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/session.html +50 -22
- {getapo-0.3.0 → getapo-0.3.2/src/getapo.egg-info}/PKG-INFO +1 -1
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/tests/test_answering.py +20 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_app.py +20 -23
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_autonomy_rules.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_background.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_browser.py +124 -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.0 → getapo-0.3.2}/tests/test_close_rows.py +1 -2
- getapo-0.3.2/tests/test_consolidation.py +84 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_continue.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_entry_points.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_folder_identity.py +131 -0
- getapo-0.3.2/tests/test_goal_page.py +31 -0
- getapo-0.3.2/tests/test_landing.py +113 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_layout_fixes.py +4 -2
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_linear_goals.py +10 -2
- getapo-0.3.2/tests/test_links.py +141 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_merge_branches.py +199 -1
- {getapo-0.3.0 → 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.0 → getapo-0.3.2}/tests/test_overview_order.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_project_home.py +2 -2
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_project_scope.py +8 -8
- {getapo-0.3.0 → 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.0 → 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.0 → getapo-0.3.2}/tests/test_task_page.py +1 -1
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_week_and_trend.py +10 -9
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_wheel.py +1 -1
- getapo-0.3.2/tests/test_work_order.py +43 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_work_tab.py +4 -3
- getapo-0.3.0/src/apo/web/templates/all_agents.html +0 -88
- getapo-0.3.0/src/apo/web/templates/all_decisions.html +0 -71
- getapo-0.3.0/src/apo/web/templates/all_work.html +0 -59
- getapo-0.3.0/src/apo/web/templates/project_agents.html +0 -42
- getapo-0.3.0/src/apo/web/templates/project_decisions.html +0 -67
- getapo-0.3.0/src/apo/web/templates/project_work.html +0 -80
- getapo-0.3.0/tests/test_decisions_tab.py +0 -59
- {getapo-0.3.0 → getapo-0.3.2}/LICENSE +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/README.md +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/THIRD_PARTY_NOTICES.md +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/pyproject.toml +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/setup.cfg +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/__main__.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/cli.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/config.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/credentials.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/installer.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/integrations/__init__.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/integrations/linear_client.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/integrations/linear_goals.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/integrations/sources.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/mcp_server.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/repo_writer.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/resources/hooks/session-decisions-nudge.sh +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/resources/skills/decisions/SKILL.md +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/transcripts.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/verify.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/__init__.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/fleet.js +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/live.js +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/notify.js +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/static/round.js +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_icons.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_prompt_form.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/_resume_actions.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/guide.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/round.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/search.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/apo/web/templates/settings.html +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/getapo.egg-info/dependency_links.txt +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/getapo.egg-info/entry_points.txt +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/getapo.egg-info/requires.txt +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/src/getapo.egg-info/top_level.txt +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_action_spec_render.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_actions.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_assets.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_bugs.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_bulk_and_views.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_cancel_button.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_changelog.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_checklist_back.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_claude_runtime.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_cli.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_cli_hooks.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_config.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_court.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_credentials.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_cross_site.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_dashboard_cli.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_db.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_decisions_skill.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_delivery.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_digest.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_due_stuck.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_edit_undo.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_events.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_guide.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_installer.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_item_folder.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_item_page.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_linear_client.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_live_stream.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_mcp_instructions.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_mcp_server.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_names.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_new_work.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_notes_labels.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_notify.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_now.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_now_leads.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_outcome_pages.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_outcomes.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_palette_js.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_poll_loop.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_preview_paths.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_priority_due.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_project_identity.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_project_overview.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_projects.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_prompt_answers.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_quiet_pages.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_rank_and_deps.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_repo_writer.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_resume_folder.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_round.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_scheduled_resume.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_schema.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_schema_upgrade.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_search.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_session_page.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_session_states.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_sessions.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_small_fixes.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_snooze.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_sources.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_station_read_api.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_status_export.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_sync_errors.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_task_attempts.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_task_effort.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_transcripts.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_ui_review.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_usage_limit.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_verify.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_weekly_report.py +0 -0
- {getapo-0.3.0 → getapo-0.3.2}/tests/test_work_items.py +0 -0
- {getapo-0.3.0 → 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 = (
|