getapo 0.3.1__tar.gz → 0.3.3__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.
Files changed (196) hide show
  1. {getapo-0.3.1/src/getapo.egg-info → getapo-0.3.3}/PKG-INFO +1 -1
  2. {getapo-0.3.1 → getapo-0.3.3}/src/apo/__init__.py +1 -1
  3. {getapo-0.3.1 → getapo-0.3.3}/src/apo/changelog.py +141 -24
  4. {getapo-0.3.1 → getapo-0.3.3}/src/apo/claude_runtime.py +45 -13
  5. {getapo-0.3.1 → getapo-0.3.3}/src/apo/cli.py +74 -0
  6. {getapo-0.3.1 → getapo-0.3.3}/src/apo/db.py +169 -10
  7. {getapo-0.3.1 → getapo-0.3.3}/src/apo/resources/guide.md +40 -33
  8. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/app.py +309 -154
  9. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/app.css +51 -3
  10. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/app.js +38 -1
  11. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/now.js +2 -2
  12. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/palette.js +26 -6
  13. getapo-0.3.3/src/apo/web/templates/_agents_board.html +65 -0
  14. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_bulk.html +1 -0
  15. getapo-0.3.3/src/apo/web/templates/_decision_log.html +31 -0
  16. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_macros.html +6 -0
  17. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_merge_result.html +1 -1
  18. getapo-0.3.3/src/apo/web/templates/_new_work.html +86 -0
  19. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_now_item.html +24 -2
  20. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_project_macros.html +14 -1
  21. getapo-0.3.3/src/apo/web/templates/_reply_form.html +20 -0
  22. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_session_card.html +6 -1
  23. getapo-0.3.1/src/apo/web/templates/week.html → getapo-0.3.3/src/apo/web/templates/_week_overview.html +9 -29
  24. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_work_location.html +4 -2
  25. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_work_main.html +15 -2
  26. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_work_status.html +1 -1
  27. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/accept.html +5 -0
  28. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/all_activity.html +1 -0
  29. getapo-0.3.3/src/apo/web/templates/all_agents.html +42 -0
  30. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/all_overview.html +0 -1
  31. getapo-0.3.3/src/apo/web/templates/all_work.html +25 -0
  32. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/base.html +9 -4
  33. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/decision.html +32 -6
  34. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/now.html +29 -1
  35. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/outcome.html +63 -41
  36. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/project_activity.html +1 -0
  37. getapo-0.3.3/src/apo/web/templates/project_agents.html +11 -0
  38. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/project_overview.html +13 -33
  39. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/project_settings.html +28 -16
  40. getapo-0.3.3/src/apo/web/templates/project_work.html +28 -0
  41. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/projects_shell.html +2 -2
  42. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/report.html +1 -0
  43. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/session.html +50 -22
  44. {getapo-0.3.1 → getapo-0.3.3/src/getapo.egg-info}/PKG-INFO +1 -1
  45. {getapo-0.3.1 → getapo-0.3.3}/src/getapo.egg-info/SOURCES.txt +17 -4
  46. getapo-0.3.3/tests/test_agents_hub.py +89 -0
  47. {getapo-0.3.1 → getapo-0.3.3}/tests/test_app.py +20 -23
  48. {getapo-0.3.1 → getapo-0.3.3}/tests/test_autonomy_rules.py +1 -1
  49. {getapo-0.3.1 → getapo-0.3.3}/tests/test_background.py +1 -1
  50. {getapo-0.3.1 → getapo-0.3.3}/tests/test_browser.py +104 -2
  51. getapo-0.3.3/tests/test_bulk_and_keys.py +45 -0
  52. getapo-0.3.3/tests/test_claude_profiles.py +310 -0
  53. {getapo-0.3.1 → getapo-0.3.3}/tests/test_cli.py +215 -0
  54. {getapo-0.3.1 → getapo-0.3.3}/tests/test_close_rows.py +1 -2
  55. getapo-0.3.3/tests/test_consolidation.py +84 -0
  56. {getapo-0.3.1 → getapo-0.3.3}/tests/test_continue.py +1 -1
  57. {getapo-0.3.1 → getapo-0.3.3}/tests/test_entry_points.py +1 -1
  58. getapo-0.3.3/tests/test_goal_page.py +31 -0
  59. getapo-0.3.3/tests/test_landing.py +192 -0
  60. {getapo-0.3.1 → getapo-0.3.3}/tests/test_layout_fixes.py +4 -2
  61. {getapo-0.3.1 → getapo-0.3.3}/tests/test_linear_goals.py +10 -2
  62. getapo-0.3.3/tests/test_links.py +141 -0
  63. {getapo-0.3.1 → getapo-0.3.3}/tests/test_merge_branches.py +199 -1
  64. {getapo-0.3.1 → getapo-0.3.3}/tests/test_navigation.py +4 -4
  65. getapo-0.3.3/tests/test_next_item.py +55 -0
  66. getapo-0.3.3/tests/test_now_scan.py +45 -0
  67. {getapo-0.3.1 → getapo-0.3.3}/tests/test_overview_order.py +1 -1
  68. {getapo-0.3.1 → getapo-0.3.3}/tests/test_project_home.py +2 -2
  69. {getapo-0.3.1 → getapo-0.3.3}/tests/test_project_scope.py +8 -8
  70. {getapo-0.3.1 → getapo-0.3.3}/tests/test_project_settings.py +61 -0
  71. getapo-0.3.3/tests/test_reply_where_you_are.py +66 -0
  72. {getapo-0.3.1 → getapo-0.3.3}/tests/test_session_verdict.py +1 -1
  73. getapo-0.3.3/tests/test_start_and_follow_up.py +155 -0
  74. {getapo-0.3.1 → getapo-0.3.3}/tests/test_task_page.py +1 -1
  75. {getapo-0.3.1 → getapo-0.3.3}/tests/test_week_and_trend.py +10 -9
  76. {getapo-0.3.1 → getapo-0.3.3}/tests/test_wheel.py +1 -1
  77. getapo-0.3.3/tests/test_work_order.py +43 -0
  78. {getapo-0.3.1 → getapo-0.3.3}/tests/test_work_tab.py +4 -3
  79. getapo-0.3.1/src/apo/web/templates/all_agents.html +0 -88
  80. getapo-0.3.1/src/apo/web/templates/all_decisions.html +0 -71
  81. getapo-0.3.1/src/apo/web/templates/all_work.html +0 -59
  82. getapo-0.3.1/src/apo/web/templates/project_agents.html +0 -42
  83. getapo-0.3.1/src/apo/web/templates/project_decisions.html +0 -67
  84. getapo-0.3.1/src/apo/web/templates/project_work.html +0 -80
  85. getapo-0.3.1/tests/test_decisions_tab.py +0 -59
  86. {getapo-0.3.1 → getapo-0.3.3}/LICENSE +0 -0
  87. {getapo-0.3.1 → getapo-0.3.3}/README.md +0 -0
  88. {getapo-0.3.1 → getapo-0.3.3}/THIRD_PARTY_NOTICES.md +0 -0
  89. {getapo-0.3.1 → getapo-0.3.3}/pyproject.toml +0 -0
  90. {getapo-0.3.1 → getapo-0.3.3}/setup.cfg +0 -0
  91. {getapo-0.3.1 → getapo-0.3.3}/src/apo/__main__.py +0 -0
  92. {getapo-0.3.1 → getapo-0.3.3}/src/apo/config.py +0 -0
  93. {getapo-0.3.1 → getapo-0.3.3}/src/apo/credentials.py +0 -0
  94. {getapo-0.3.1 → getapo-0.3.3}/src/apo/installer.py +0 -0
  95. {getapo-0.3.1 → getapo-0.3.3}/src/apo/integrations/__init__.py +0 -0
  96. {getapo-0.3.1 → getapo-0.3.3}/src/apo/integrations/linear_client.py +0 -0
  97. {getapo-0.3.1 → getapo-0.3.3}/src/apo/integrations/linear_goals.py +0 -0
  98. {getapo-0.3.1 → getapo-0.3.3}/src/apo/integrations/sources.py +0 -0
  99. {getapo-0.3.1 → getapo-0.3.3}/src/apo/mcp_server.py +0 -0
  100. {getapo-0.3.1 → getapo-0.3.3}/src/apo/repo_writer.py +0 -0
  101. {getapo-0.3.1 → getapo-0.3.3}/src/apo/resources/hooks/session-decisions-nudge.sh +0 -0
  102. {getapo-0.3.1 → getapo-0.3.3}/src/apo/resources/skills/decisions/SKILL.md +0 -0
  103. {getapo-0.3.1 → getapo-0.3.3}/src/apo/transcripts.py +0 -0
  104. {getapo-0.3.1 → getapo-0.3.3}/src/apo/verify.py +0 -0
  105. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/__init__.py +0 -0
  106. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/fleet.js +0 -0
  107. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/live.js +0 -0
  108. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/notify.js +0 -0
  109. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/static/round.js +0 -0
  110. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_attachment_composer.html +0 -0
  111. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_icons.html +0 -0
  112. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_prompt_form.html +0 -0
  113. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/_resume_actions.html +0 -0
  114. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/guide.html +0 -0
  115. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/round.html +0 -0
  116. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/search.html +0 -0
  117. {getapo-0.3.1 → getapo-0.3.3}/src/apo/web/templates/settings.html +0 -0
  118. {getapo-0.3.1 → getapo-0.3.3}/src/getapo.egg-info/dependency_links.txt +0 -0
  119. {getapo-0.3.1 → getapo-0.3.3}/src/getapo.egg-info/entry_points.txt +0 -0
  120. {getapo-0.3.1 → getapo-0.3.3}/src/getapo.egg-info/requires.txt +0 -0
  121. {getapo-0.3.1 → getapo-0.3.3}/src/getapo.egg-info/top_level.txt +0 -0
  122. {getapo-0.3.1 → getapo-0.3.3}/tests/test_action_spec_render.py +0 -0
  123. {getapo-0.3.1 → getapo-0.3.3}/tests/test_actions.py +0 -0
  124. {getapo-0.3.1 → getapo-0.3.3}/tests/test_answering.py +0 -0
  125. {getapo-0.3.1 → getapo-0.3.3}/tests/test_assets.py +0 -0
  126. {getapo-0.3.1 → getapo-0.3.3}/tests/test_bugs.py +0 -0
  127. {getapo-0.3.1 → getapo-0.3.3}/tests/test_bulk_and_views.py +0 -0
  128. {getapo-0.3.1 → getapo-0.3.3}/tests/test_cancel_button.py +0 -0
  129. {getapo-0.3.1 → getapo-0.3.3}/tests/test_changelog.py +0 -0
  130. {getapo-0.3.1 → getapo-0.3.3}/tests/test_checklist_back.py +0 -0
  131. {getapo-0.3.1 → getapo-0.3.3}/tests/test_claude_runtime.py +0 -0
  132. {getapo-0.3.1 → getapo-0.3.3}/tests/test_cli_hooks.py +0 -0
  133. {getapo-0.3.1 → getapo-0.3.3}/tests/test_config.py +0 -0
  134. {getapo-0.3.1 → getapo-0.3.3}/tests/test_court.py +0 -0
  135. {getapo-0.3.1 → getapo-0.3.3}/tests/test_credentials.py +0 -0
  136. {getapo-0.3.1 → getapo-0.3.3}/tests/test_cross_site.py +0 -0
  137. {getapo-0.3.1 → getapo-0.3.3}/tests/test_dashboard_cli.py +0 -0
  138. {getapo-0.3.1 → getapo-0.3.3}/tests/test_db.py +0 -0
  139. {getapo-0.3.1 → getapo-0.3.3}/tests/test_decisions_skill.py +0 -0
  140. {getapo-0.3.1 → getapo-0.3.3}/tests/test_delivery.py +0 -0
  141. {getapo-0.3.1 → getapo-0.3.3}/tests/test_digest.py +0 -0
  142. {getapo-0.3.1 → getapo-0.3.3}/tests/test_due_stuck.py +0 -0
  143. {getapo-0.3.1 → getapo-0.3.3}/tests/test_edit_undo.py +0 -0
  144. {getapo-0.3.1 → getapo-0.3.3}/tests/test_events.py +0 -0
  145. {getapo-0.3.1 → getapo-0.3.3}/tests/test_folder_identity.py +0 -0
  146. {getapo-0.3.1 → getapo-0.3.3}/tests/test_guide.py +0 -0
  147. {getapo-0.3.1 → getapo-0.3.3}/tests/test_installer.py +0 -0
  148. {getapo-0.3.1 → getapo-0.3.3}/tests/test_item_folder.py +0 -0
  149. {getapo-0.3.1 → getapo-0.3.3}/tests/test_item_page.py +0 -0
  150. {getapo-0.3.1 → getapo-0.3.3}/tests/test_linear_client.py +0 -0
  151. {getapo-0.3.1 → getapo-0.3.3}/tests/test_live_stream.py +0 -0
  152. {getapo-0.3.1 → getapo-0.3.3}/tests/test_mcp_instructions.py +0 -0
  153. {getapo-0.3.1 → getapo-0.3.3}/tests/test_mcp_server.py +0 -0
  154. {getapo-0.3.1 → getapo-0.3.3}/tests/test_names.py +0 -0
  155. {getapo-0.3.1 → getapo-0.3.3}/tests/test_new_work.py +0 -0
  156. {getapo-0.3.1 → getapo-0.3.3}/tests/test_notes_labels.py +0 -0
  157. {getapo-0.3.1 → getapo-0.3.3}/tests/test_notify.py +0 -0
  158. {getapo-0.3.1 → getapo-0.3.3}/tests/test_now.py +0 -0
  159. {getapo-0.3.1 → getapo-0.3.3}/tests/test_now_leads.py +0 -0
  160. {getapo-0.3.1 → getapo-0.3.3}/tests/test_outcome_pages.py +0 -0
  161. {getapo-0.3.1 → getapo-0.3.3}/tests/test_outcomes.py +0 -0
  162. {getapo-0.3.1 → getapo-0.3.3}/tests/test_palette_js.py +0 -0
  163. {getapo-0.3.1 → getapo-0.3.3}/tests/test_poll_loop.py +0 -0
  164. {getapo-0.3.1 → getapo-0.3.3}/tests/test_preview_paths.py +0 -0
  165. {getapo-0.3.1 → getapo-0.3.3}/tests/test_priority_due.py +0 -0
  166. {getapo-0.3.1 → getapo-0.3.3}/tests/test_project_identity.py +0 -0
  167. {getapo-0.3.1 → getapo-0.3.3}/tests/test_project_overview.py +0 -0
  168. {getapo-0.3.1 → getapo-0.3.3}/tests/test_projects.py +0 -0
  169. {getapo-0.3.1 → getapo-0.3.3}/tests/test_prompt_answers.py +0 -0
  170. {getapo-0.3.1 → getapo-0.3.3}/tests/test_quiet_pages.py +0 -0
  171. {getapo-0.3.1 → getapo-0.3.3}/tests/test_rank_and_deps.py +0 -0
  172. {getapo-0.3.1 → getapo-0.3.3}/tests/test_repo_writer.py +0 -0
  173. {getapo-0.3.1 → getapo-0.3.3}/tests/test_resume_folder.py +0 -0
  174. {getapo-0.3.1 → getapo-0.3.3}/tests/test_round.py +0 -0
  175. {getapo-0.3.1 → getapo-0.3.3}/tests/test_scheduled_resume.py +0 -0
  176. {getapo-0.3.1 → getapo-0.3.3}/tests/test_schema.py +0 -0
  177. {getapo-0.3.1 → getapo-0.3.3}/tests/test_schema_upgrade.py +0 -0
  178. {getapo-0.3.1 → getapo-0.3.3}/tests/test_search.py +0 -0
  179. {getapo-0.3.1 → getapo-0.3.3}/tests/test_session_page.py +0 -0
  180. {getapo-0.3.1 → getapo-0.3.3}/tests/test_session_states.py +0 -0
  181. {getapo-0.3.1 → getapo-0.3.3}/tests/test_sessions.py +0 -0
  182. {getapo-0.3.1 → getapo-0.3.3}/tests/test_small_fixes.py +0 -0
  183. {getapo-0.3.1 → getapo-0.3.3}/tests/test_snooze.py +0 -0
  184. {getapo-0.3.1 → getapo-0.3.3}/tests/test_sources.py +0 -0
  185. {getapo-0.3.1 → getapo-0.3.3}/tests/test_station_read_api.py +0 -0
  186. {getapo-0.3.1 → getapo-0.3.3}/tests/test_status_export.py +0 -0
  187. {getapo-0.3.1 → getapo-0.3.3}/tests/test_sync_errors.py +0 -0
  188. {getapo-0.3.1 → getapo-0.3.3}/tests/test_task_attempts.py +0 -0
  189. {getapo-0.3.1 → getapo-0.3.3}/tests/test_task_effort.py +0 -0
  190. {getapo-0.3.1 → getapo-0.3.3}/tests/test_transcripts.py +0 -0
  191. {getapo-0.3.1 → getapo-0.3.3}/tests/test_ui_review.py +0 -0
  192. {getapo-0.3.1 → getapo-0.3.3}/tests/test_usage_limit.py +0 -0
  193. {getapo-0.3.1 → getapo-0.3.3}/tests/test_verify.py +0 -0
  194. {getapo-0.3.1 → getapo-0.3.3}/tests/test_weekly_report.py +0 -0
  195. {getapo-0.3.1 → getapo-0.3.3}/tests/test_work_items.py +0 -0
  196. {getapo-0.3.1 → getapo-0.3.3}/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.1
3
+ Version: 0.3.3
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/
@@ -1,3 +1,3 @@
1
1
  """apo (AI Project Orchestration): a local dashboard and MCP server for Claude Code."""
2
2
 
3
- __version__ = "0.3.1"
3
+ __version__ = "0.3.3"
@@ -4,6 +4,7 @@ requests need the network, so they're fetched in the background and pages only e
4
4
  read the cache."""
5
5
  import json
6
6
  import os
7
+ import re
7
8
  import shlex
8
9
  import subprocess
9
10
  import tempfile
@@ -89,7 +90,8 @@ def work_location(path: str) -> dict | None:
89
90
  "default_branch": default, "merged": merged_into(path, commit, default) if default else None}
90
91
 
91
92
 
92
- # Ahead/behind counts and the conflict check depend only on the two commits, so a page
93
+ # Ahead/behind counts and the merge preview depend only on the two commits (for a branch
94
+ # with no history in common, also on the other local branches: close enough), so a page
93
95
  # re-rendered on every database change asks git once per pair, not once per render.
94
96
  _branch_cache: dict[tuple[str, str, str], dict] = {}
95
97
 
@@ -116,9 +118,11 @@ def worktrees(path: str) -> list[dict]:
116
118
  found: list[dict] = []
117
119
  for line in out.stdout.splitlines():
118
120
  if line.startswith("worktree "):
119
- found.append({"path": line[len("worktree "):], "branch": None})
121
+ found.append({"path": line[len("worktree "):], "branch": None, "locked": None})
120
122
  elif line.startswith("branch refs/heads/") and found:
121
123
  found[-1]["branch"] = line[len("branch refs/heads/"):]
124
+ elif (line == "locked" or line.startswith("locked ")) and found:
125
+ found[-1]["locked"] = line[len("locked "):] or "locked"
122
126
  return found
123
127
 
124
128
 
@@ -146,24 +150,59 @@ def merge_command(path: str, branch: str, default: str, checkout: str | None) ->
146
150
  return f"git merge --no-edit {shlex.quote(branch)}, in a temporary checkout of {default}"
147
151
 
148
152
 
149
- def _would_conflict(path: str, default_sha: str, branch_sha: str) -> list[str]:
150
- """Files a merge would leave conflicted, from git's trivial three-way merge-tree. A hint
151
- for the list, not a promise: merge_branch finds out for sure, and backs out."""
152
- base = _git(path, "merge-base", default_sha, branch_sha)
153
- if not base or base.returncode != 0 or not base.stdout.strip():
154
- return []
155
- out = _git(path, "merge-tree", base.stdout.strip(), default_sha, branch_sha)
153
+ def _merge_base(path: str, a: str, b: str) -> str | None:
154
+ """The commit a and b last had in common: "" when they share no history, None when git
155
+ can't say."""
156
+ out = _git(path, "merge-base", a, b)
157
+ if not out or out.returncode not in (0, 1):
158
+ return None
159
+ return out.stdout.strip()
160
+
161
+
162
+ def _merge_preview(path: str, default_sha: str, branch_sha: str) -> dict:
163
+ """What merging the branch would do, from git's trivial three-way merge-tree: the files
164
+ it would likely leave conflicted, and whether it would change the default branch at
165
+ all (a squash-merged branch wouldn't). A hint for the list, not a promise: merge_branch
166
+ finds out for sure, and backs out. Anything git warns about counts as a change."""
167
+ base = _merge_base(path, default_sha, branch_sha)
168
+ if base == "":
169
+ return {"unrelated": True, "conflicts": [], "in_default": _in_default_files(path, default_sha, branch_sha)}
170
+ unknown = {"unrelated": False, "conflicts": [], "in_default": False}
171
+ out = _git(path, "merge-tree", base, default_sha, branch_sha) if base else None
156
172
  if not out or out.returncode != 0:
157
- return []
173
+ return unknown
158
174
  files: list[str] = []
159
175
  current = None
176
+ modes: dict[str, str] = {}
177
+ changes = bool(out.stderr.strip())
160
178
  for line in out.stdout.splitlines():
161
179
  if line.startswith((" base ", " our ", " their ", " result ")):
162
180
  parts = line.split(None, 3)
163
181
  current = parts[3] if len(parts) == 4 else None
164
- elif line.startswith("+<<<<<<<") and current and current not in files:
165
- files.append(current)
166
- return files
182
+ modes[parts[0]] = parts[1]
183
+ if parts[0] == "their" and parts[1] not in (modes.get("our"), modes.get("base")):
184
+ changes = True
185
+ elif line.startswith(("+", "-")):
186
+ changes = True
187
+ if line.startswith("+<<<<<<<") and current and current not in files:
188
+ files.append(current)
189
+ elif line and not line.startswith((" ", "@", "\\")):
190
+ changes = changes or line != "changed in both"
191
+ modes = {}
192
+ return {**unknown, "conflicts": files, "in_default": not changes}
193
+
194
+
195
+ def _in_default_files(path: str, default_sha: str, branch_sha: str) -> bool:
196
+ """For a branch with no history in common with the default branch: whether it's part of
197
+ a local branch whose files the default branch has had, as the old branches are when the
198
+ default branch was restarted as a fresh commit of the old history's files."""
199
+ trees = _git(path, "rev-list", "--format=%T", default_sha)
200
+ heads = _git(path, "for-each-ref", "--format=%(objectname) %(tree)", "refs/heads")
201
+ if not trees or trees.returncode != 0 or not heads or heads.returncode != 0:
202
+ return False
203
+ had = {line for line in trees.stdout.splitlines() if not line.startswith("commit ")}
204
+ return any(_is_ancestor(path, branch_sha, head) for head, _, tree in
205
+ (line.partition(" ") for line in heads.stdout.splitlines()) if tree in had)
167
206
 
168
207
 
169
208
  def _pair_state(path: str, default_sha: str, branch_sha: str) -> dict | None:
@@ -175,17 +214,23 @@ def _pair_state(path: str, default_sha: str, branch_sha: str) -> dict | None:
175
214
  behind, ahead = (int(n) for n in out.stdout.split())
176
215
  if len(_branch_cache) > 500:
177
216
  _branch_cache.clear()
178
- _branch_cache[key] = {"ahead": ahead, "behind": behind,
179
- "conflicts": _would_conflict(path, default_sha, branch_sha) if ahead else []}
217
+ preview = {"unrelated": False, "conflicts": [], "in_default": not ahead}
218
+ # Not behind is a fast-forward: nothing can have reached the default branch another way.
219
+ if ahead and behind:
220
+ preview = _merge_preview(path, default_sha, branch_sha)
221
+ _branch_cache[key] = {"ahead": ahead, "behind": behind, **preview}
180
222
  state = _branch_cache[key]
181
223
  return {**state, "conflicts": list(state["conflicts"])}
182
224
 
183
225
 
184
226
  def mergeable_branches(path: str) -> dict:
185
- """Local branches with commits the default branch doesn't have, newest first: what
186
- agents finished in worktrees and nobody has merged yet. checkout is where the default
187
- branch is checked out (the merge happens there), blocked why it can't happen now,
188
- main_checkout the repository's own folder as opposed to its added worktrees."""
227
+ """Local branches with work the default branch doesn't have, newest first: what agents
228
+ finished in worktrees and nobody has merged yet. Work that reached the default branch
229
+ another way (squash-merged, or the default branch restarted from its files) isn't
230
+ listed; a branch with no history in common is, marked unrelated, since git won't merge
231
+ it. checkout is where the default branch is checked out (the merge happens there),
232
+ blocked why it can't happen now, main_checkout the repository's own folder as opposed
233
+ to its added worktrees."""
189
234
  listing = {"default_branch": None, "checkout": None, "main_checkout": None, "blocked": None, "branches": []}
190
235
  default = default_branch(path)
191
236
  default_sha = _sha(path, f"refs/heads/{default}") if default else None
@@ -207,14 +252,14 @@ def mergeable_branches(path: str) -> dict:
207
252
  ref, sha, at, subject = parts
208
253
  name = ref[len("refs/heads/"):]
209
254
  state = _pair_state(path, default_sha, sha)
210
- if name == default or not state or not state["ahead"]:
255
+ if name == default or not state or state["in_default"]:
211
256
  continue
212
257
  listing["branches"].append({
213
258
  "branch": name, "commit": sha, "subject": subject,
214
259
  "at": datetime.fromisoformat(at).astimezone(timezone.utc).isoformat(),
215
260
  "worktree": checked_out.get(name), "command": merge_command(path, name, default, checkout), **state,
216
261
  })
217
- if listing["branches"]:
262
+ if any(not b["unrelated"] for b in listing["branches"]):
218
263
  listing["blocked"] = _blocked(default, checkout)
219
264
  return listing
220
265
 
@@ -231,9 +276,10 @@ def branch_state(path: str, branch: str) -> dict | None:
231
276
  if state is None:
232
277
  return None
233
278
  checkout = _checkout_of(path, default)
234
- return {"branch": branch, "commit": branch_sha, "default_branch": default, "merged": not state["ahead"],
279
+ mergeable = not state["in_default"] and not state["unrelated"]
280
+ return {"branch": branch, "commit": branch_sha, "default_branch": default, "merged": state["in_default"],
235
281
  "checkout": checkout,
236
- "blocked": _blocked(default, checkout) if state["ahead"] else None,
282
+ "blocked": _blocked(default, checkout) if mergeable else None,
237
283
  "command": merge_command(path, branch, default, checkout), **state}
238
284
 
239
285
 
@@ -271,7 +317,8 @@ def merge_branch(path: str, branch: str) -> dict:
271
317
  in the checkout that has the default branch, which must have no uncommitted changes
272
318
  to tracked files. With the default branch checked out nowhere, a fast-forward just
273
319
  moves it, and anything else merges in a temporary checkout removed afterwards. A
274
- conflict is backed out, leaving everything as it was."""
320
+ conflict is backed out, leaving everything as it was. A branch with no history in
321
+ common is refused: forcing it would bring that whole history into the default branch."""
275
322
  result = {"ok": False, "error": None, "branch": branch, "into": None, "checkout": None, "commit": None,
276
323
  "fast_forward": False, "already": False, "conflicts": []}
277
324
  default = default_branch(path)
@@ -284,6 +331,9 @@ def merge_branch(path: str, branch: str) -> dict:
284
331
  return {**result, "error": f"There's no other local branch named {branch!r} to merge into {default}."}
285
332
  if _is_ancestor(path, branch_sha, default_sha):
286
333
  return {**result, "ok": True, "already": True, "commit": default_sha}
334
+ if _merge_base(path, default_sha, branch_sha) == "":
335
+ return {**result, "error": f"{branch} has no history in common with {default}, so apo won't merge it. "
336
+ f"Nothing was changed."}
287
337
  checkout = _checkout_of(path, default)
288
338
  if checkout:
289
339
  blocked = _blocked(default, checkout)
@@ -309,6 +359,73 @@ def merge_branch(path: str, branch: str) -> dict:
309
359
  _git(path, "worktree", "prune")
310
360
 
311
361
 
362
+ _CLAUDE_LOCK = re.compile(r"claude agent \S+ \(pid (\d+)(?: start (\d+))?\)")
363
+
364
+
365
+ def _process_alive(pid: int, start: str | None) -> bool:
366
+ """Whether pid is still the process that took the lock: start is its start time in
367
+ /proc/<pid>/stat, so a pid the system has since handed to another process counts as ended."""
368
+ try:
369
+ os.kill(pid, 0)
370
+ except ProcessLookupError:
371
+ return False
372
+ except PermissionError:
373
+ pass
374
+ if not start:
375
+ return True
376
+ try:
377
+ fields = Path(f"/proc/{pid}/stat").read_text().rsplit(")", 1)[1].split()
378
+ except (OSError, IndexError):
379
+ return True
380
+ return len(fields) > 19 and fields[19] == start
381
+
382
+
383
+ def _lock_in_the_way(lock: str, finished: bool) -> str | None:
384
+ """Why a locked worktree stays, or None when its lock can be lifted: Claude Code locks
385
+ a subagent's worktree for as long as the session that started it runs."""
386
+ claude = _CLAUDE_LOCK.search(lock)
387
+ if not claude:
388
+ return f"it's locked ({lock})"
389
+ if finished or not _process_alive(int(claude.group(1)), claude.group(2)):
390
+ return None
391
+ return "a Claude Code session still holds it"
392
+
393
+
394
+ def clean_up_branch(path: str, branch: str, finished: bool = False) -> dict:
395
+ """After a merge: remove the added worktree the branch is checked out in, then delete
396
+ the branch, with git's own safety: a worktree with changes or untracked files stays,
397
+ and so does a branch git doesn't count as merged. The repository's own folder is never
398
+ removed. finished says the item's work is done, so a live Claude session's lock on the
399
+ worktree no longer keeps it."""
400
+ result = {"worktree": None, "worktree_removed": False, "branch_deleted": False, "error": None}
401
+ trees = worktrees(path)
402
+ main = trees[0]["path"] if trees else None
403
+ tree = next((w for w in trees if w["branch"] == branch), None)
404
+ where = tree["path"] if tree else None
405
+ if where and where == main:
406
+ return {**result, "error": f"{branch} is checked out in the repository's own folder, so it was kept."}
407
+ if where:
408
+ result["worktree"] = where
409
+ lock = tree.get("locked")
410
+ if lock:
411
+ why = _lock_in_the_way(lock, finished)
412
+ if why:
413
+ return {**result, "error": f"Kept {branch} and its worktree: {why}."}
414
+ _git(path, "worktree", "unlock", where)
415
+ out = _git(path, "worktree", "remove", where)
416
+ if not out or out.returncode != 0:
417
+ if lock:
418
+ _git(path, "worktree", "lock", "--reason", lock, where)
419
+ reason = (out.stderr.strip() if out else "") or "git failed"
420
+ return {**result, "error": f"Kept the worktree {_home(where)}: {reason}"}
421
+ result["worktree_removed"] = True
422
+ out = _git(path, "branch", "-d", branch)
423
+ if not out or out.returncode != 0:
424
+ reason = (out.stderr.strip() if out else "") or "git failed"
425
+ return {**result, "error": f"Kept the branch {branch}: {reason}"}
426
+ return {**result, "branch_deleted": True}
427
+
428
+
312
429
  def has_pull_requests_cache(path: str) -> bool:
313
430
  return os.path.realpath(path) in _pr_cache
314
431
 
@@ -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 index, folder in enumerate(claude_config_dirs()):
99
- # This process's own profile runs with the environment untouched: setting
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) -> str:
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
- _run(["stop", agent_id], None, timeout)
182
- return True
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 = (
@@ -6,6 +6,8 @@ Claude Code calls, and a command line for agents and scripts that can't use MCP.
6
6
  import argparse
7
7
  import json
8
8
  import os
9
+ import re
10
+ import shutil
9
11
  import signal
10
12
  import socket
11
13
  import subprocess
@@ -155,6 +157,60 @@ def _cmd_list(args: argparse.Namespace) -> None:
155
157
  print()
156
158
 
157
159
 
160
+ def _search_query(words: list[str]) -> str:
161
+ """A shell-quoted argument with a space in it stays one phrase, as "two words" does in the dashboard."""
162
+ return " ".join(f'"{w}"' if len(w.split()) > 1 and '"' not in w else w for w in words)
163
+
164
+
165
+ def _search_date(value: str | None) -> str | None:
166
+ if value and re.fullmatch(r"\d{1,4}[dw]", value.strip().lower()):
167
+ return db.parse_since(value).astimezone(timezone.utc).date().isoformat()
168
+ return value
169
+
170
+
171
+ def _cmd_search(args: argparse.Namespace) -> None:
172
+ conn = db.get_connection()
173
+ filters = {"status": args.status, "project": args.project, "owner": args.owner, "label": args.label,
174
+ "since": args.since, "until": args.until}
175
+ if args.transcripts:
176
+ query = " ".join(args.words).strip()
177
+ if any(filters.values()):
178
+ args.usage_error("--transcripts takes no filters, only --limit and --json")
179
+ if len(query) < 3:
180
+ args.usage_error("--transcripts needs at least three characters to look for")
181
+ if not shutil.which("rg"):
182
+ print("Searching transcripts needs ripgrep (rg) on your PATH.", file=sys.stderr)
183
+ sys.exit(1)
184
+ hits = db.search_transcripts(conn, query, limit=args.limit)
185
+ else:
186
+ query = _search_query(args.words)
187
+ if not query.strip() and not any(filters.values()):
188
+ args.usage_error("give some words to look for, or a filter")
189
+ if args.project:
190
+ project = db.find_project(conn, args.project)
191
+ if project is None:
192
+ print(f"No project named '{args.project}'.", file=sys.stderr)
193
+ sys.exit(1)
194
+ filters["project"] = project["name"]
195
+ try:
196
+ filters["since"], filters["until"] = _search_date(args.since), _search_date(args.until)
197
+ hits = db.search_filtered(conn, query, **filters, limit=args.limit)
198
+ except ValueError as exc:
199
+ print(exc, file=sys.stderr)
200
+ sys.exit(1)
201
+ if args.json:
202
+ print(json.dumps(hits))
203
+ return
204
+ if not hits:
205
+ print("Nothing found.")
206
+ return
207
+ rows = [(h["subkind"], f"#{h['ref']}" if h["kind"] == "item" else (h.get("session_id") or "")[:8],
208
+ h["status"].upper(), h["project_name"] or "-", " ".join(h["title"].split())) for h in hits]
209
+ widths = [max(len(row[i]) for row in rows) for i in range(4)]
210
+ for row in rows:
211
+ print(" ".join(cell.ljust(width) for cell, width in zip(row, widths)) + " " + row[4])
212
+
213
+
158
214
  def _cmd_show(args: argparse.Namespace) -> None:
159
215
  conn = db.get_connection()
160
216
  decision = db.get_decision_request(conn, args.decision_id)
@@ -1073,6 +1129,24 @@ def main(argv: list[str] | None = None) -> None:
1073
1129
  lst.add_argument("--json", action="store_true", help="Emit JSON instead of human-readable text")
1074
1130
  lst.set_defaults(func=_cmd_list)
1075
1131
 
1132
+ search_p = sub.add_parser("search", help="Search items, session recaps and goals, as the dashboard's search does")
1133
+ search_p.add_argument("words", nargs="*",
1134
+ help='Words that all have to match ("two words" quoted is one phrase); 447 finds item #447, '
1135
+ "the start of a session's id finds that session")
1136
+ search_p.add_argument("--status", default=None,
1137
+ help="An item's open, in_progress, answered, resolved or cancelled; a session's running, "
1138
+ "idle or ended; a goal's active, paused, achieved or dropped")
1139
+ search_p.add_argument("--project", default=None)
1140
+ search_p.add_argument("--owner", choices=["me", "agent", "external"], default=None, help="Items only")
1141
+ search_p.add_argument("--label", default=None, help="Items only")
1142
+ search_p.add_argument("--since", default=None, help="Created on or after: YYYY-MM-DD, or 7d, 2w")
1143
+ search_p.add_argument("--until", default=None, help="Created on or before: YYYY-MM-DD, or 7d, 2w")
1144
+ search_p.add_argument("--limit", type=int, default=50, help="At most this many of each kind (default 50)")
1145
+ search_p.add_argument("--transcripts", action="store_true",
1146
+ help="Search session transcripts instead (needs ripgrep; takes no filters)")
1147
+ search_p.add_argument("--json", action="store_true", help="Emit JSON instead of human-readable text")
1148
+ search_p.set_defaults(func=_cmd_search, usage_error=search_p.error)
1149
+
1076
1150
  show = sub.add_parser("show", help="Show full detail for one decision request")
1077
1151
  show.add_argument("decision_id", type=int)
1078
1152
  show.add_argument("--json", action="store_true", help="Emit JSON instead of human-readable text")