txcode-sdk 1.0.0__tar.gz → 1.1.0__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 (197) hide show
  1. {txcode_sdk-1.0.0/src/txcode_sdk.egg-info → txcode_sdk-1.1.0}/PKG-INFO +1 -1
  2. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/pyproject.toml +1 -1
  3. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/ws_server.py +1 -13
  4. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/__init__.py +1 -1
  5. txcode_sdk-1.1.0/src/txcode_sdk/agent/base_agent.py +391 -0
  6. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/chat/chat_agent.py +5 -5
  7. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/code/code_agent.py +6 -5
  8. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/common/common_agent.py +5 -5
  9. txcode_sdk-1.1.0/src/txcode_sdk/agent/compact_mixin.py +91 -0
  10. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/design/design_agent.py +6 -5
  11. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/discuss/discuss_agent.py +6 -5
  12. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/dream/dream_agent.py +6 -5
  13. txcode_sdk-1.1.0/src/txcode_sdk/agent/factory.py +105 -0
  14. txcode_sdk-1.1.0/src/txcode_sdk/agent/hook_mixin.py +38 -0
  15. txcode_sdk-1.1.0/src/txcode_sdk/agent/message_utils.py +97 -0
  16. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/name/name_agent.py +14 -1
  17. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/plan/plan_agent.py +40 -39
  18. txcode_sdk-1.1.0/src/txcode_sdk/agent/prompt_builder.py +91 -0
  19. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/shell/shell_agent.py +6 -5
  20. txcode_sdk-1.1.0/src/txcode_sdk/agent/step_utils.py +121 -0
  21. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/task/task_agent.py +6 -5
  22. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/test/test_agent.py +6 -5
  23. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/client.py +13 -116
  24. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/__main__.py +69 -68
  25. txcode_sdk-1.1.0/src/txcode_sdk/server/git.py +148 -0
  26. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/handler.py +535 -593
  27. txcode_sdk-1.1.0/src/txcode_sdk/server/http/__init__.py +114 -0
  28. txcode_sdk-1.1.0/src/txcode_sdk/server/http/chat_routes.py +64 -0
  29. txcode_sdk-1.1.0/src/txcode_sdk/server/http/file_routes.py +88 -0
  30. txcode_sdk-1.1.0/src/txcode_sdk/server/http/git_routes.py +67 -0
  31. txcode_sdk-1.1.0/src/txcode_sdk/server/http/http_base.py +382 -0
  32. txcode_sdk-1.1.0/src/txcode_sdk/server/http/plan_code_routes.py +66 -0
  33. txcode_sdk-1.1.0/src/txcode_sdk/server/http/project_routes.py +72 -0
  34. txcode_sdk-1.1.0/src/txcode_sdk/server/http/session_routes.py +65 -0
  35. txcode_sdk-1.1.0/src/txcode_sdk/server/http/skill_routes.py +67 -0
  36. txcode_sdk-1.1.0/src/txcode_sdk/server/http/spec_routes.py +89 -0
  37. txcode_sdk-1.1.0/src/txcode_sdk/server/http/sys_config_routes.py +308 -0
  38. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/plan_code.py +223 -234
  39. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/project_manager.py +11 -10
  40. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/provider_config.py +1 -5
  41. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/server.py +6 -0
  42. txcode_sdk-1.1.0/src/txcode_sdk/server/services/__init__.py +26 -0
  43. txcode_sdk-1.1.0/src/txcode_sdk/server/services/broadcaster.py +38 -0
  44. txcode_sdk-1.1.0/src/txcode_sdk/server/services/project_service.py +48 -0
  45. txcode_sdk-1.1.0/src/txcode_sdk/server/services/provider_service.py +126 -0
  46. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/skill_manager.py +3 -6
  47. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/spec_manager.py +5 -12
  48. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/session/manager.py +1 -32
  49. txcode_sdk-1.1.0/src/txcode_sdk/tools/__init__.py +15 -0
  50. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/edit_file.py +13 -351
  51. txcode_sdk-1.1.0/src/txcode_sdk/tools/edit_replacers.py +329 -0
  52. txcode_sdk-1.1.0/src/txcode_sdk/tools/edit_similarity.py +20 -0
  53. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/glob.py +1 -9
  54. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/grep.py +1 -9
  55. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/read_file.py +101 -110
  56. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/write_file.py +42 -52
  57. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/types.py +159 -158
  58. txcode_sdk-1.1.0/src/txcode_sdk/utils/__init__.py +19 -0
  59. txcode_sdk-1.1.0/src/txcode_sdk/utils/format.py +43 -0
  60. txcode_sdk-1.1.0/src/txcode_sdk/utils/log.py +43 -0
  61. txcode_sdk-1.1.0/src/txcode_sdk/utils/path_util.py +30 -0
  62. txcode_sdk-1.1.0/src/txcode_sdk/utils/time_util.py +23 -0
  63. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0/src/txcode_sdk.egg-info}/PKG-INFO +1 -1
  64. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk.egg-info/SOURCES.txt +30 -6
  65. txcode_sdk-1.0.0/src/txcode_sdk/agent/base_agent.py +0 -603
  66. txcode_sdk-1.0.0/src/txcode_sdk/server/http.py +0 -1071
  67. txcode_sdk-1.0.0/src/txcode_sdk/tools/__init__.py +0 -3
  68. txcode_sdk-1.0.0/src/txcode_sdk/tools/bash_tool.py +0 -5
  69. txcode_sdk-1.0.0/src/txcode_sdk/tools/glob_tool.py +0 -5
  70. txcode_sdk-1.0.0/src/txcode_sdk/tools/grep_tool.py +0 -5
  71. txcode_sdk-1.0.0/src/txcode_sdk/tools/memory_tool.py +0 -5
  72. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/LICENSE +0 -0
  73. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/README.md +0 -0
  74. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/setup.cfg +0 -0
  75. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/setup.py +0 -0
  76. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/__init__.py +0 -0
  77. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/code_example.py +0 -0
  78. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/code_session.py +0 -0
  79. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/code_tool.py +0 -0
  80. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/constants.py +0 -0
  81. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/example/query_session.py +0 -0
  82. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/_compat/__init__.py +0 -0
  83. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/_compat/dataclasses.py +0 -0
  84. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/_compat/resources.py +0 -0
  85. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/__init__.py +0 -0
  86. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/chat/__init__.py +0 -0
  87. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
  88. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
  89. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
  90. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/code/__init__.py +0 -0
  91. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
  92. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
  93. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
  94. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/common/__init__.py +0 -0
  95. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
  96. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
  97. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/design/__init__.py +0 -0
  98. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
  99. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
  100. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
  101. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
  102. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
  103. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
  104. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
  105. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/dream/__init__.py +0 -0
  106. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
  107. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
  108. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
  109. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/mem/__init__.py +0 -0
  110. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
  111. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
  112. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
  113. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
  114. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/name/__init__.py +0 -0
  115. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
  116. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
  117. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/plan/__init__.py +0 -0
  118. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
  119. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
  120. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
  121. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/shell/__init__.py +0 -0
  122. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
  123. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
  124. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
  125. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/skill/__init__.py +0 -0
  126. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
  127. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
  128. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
  129. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
  130. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
  131. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
  132. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
  133. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +0 -0
  134. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/task/__init__.py +0 -0
  135. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
  136. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
  137. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
  138. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/test/__init__.py +0 -0
  139. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
  140. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
  141. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
  142. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/agent/tool_registry.py +0 -0
  143. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/compact/__init__.py +0 -0
  144. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/compact/compressor.py +0 -0
  145. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/config/__init__.py +0 -0
  146. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/config/context_config.py +0 -0
  147. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/__init__.py +0 -0
  148. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
  149. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/handlers/base.py +0 -0
  150. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
  151. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/processor.py +0 -0
  152. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/queue.py +0 -0
  153. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/hooks/types.py +0 -0
  154. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/__init__.py +0 -0
  155. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/base.py +0 -0
  156. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/deepseek_provider.py +0 -0
  157. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/openai_provider.py +0 -0
  158. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/router.py +0 -0
  159. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/provider/txcode_ai.py +0 -0
  160. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/__init__.py +0 -0
  161. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/config_store.py +0 -0
  162. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/hub_client.py +0 -0
  163. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/json_store.py +0 -0
  164. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/websocket.py +0 -0
  165. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/server/zip_utils.py +0 -0
  166. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/session/__init__.py +0 -0
  167. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/skills/__init__.py +0 -0
  168. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/specs/__init__.py +0 -0
  169. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/_util.py +0 -0
  170. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/bash.py +0 -0
  171. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/bash.txt +0 -0
  172. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/code_search.py +0 -0
  173. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/code_search.txt +0 -0
  174. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/edit_file.txt +0 -0
  175. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/email_tool.py +0 -0
  176. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/email_tool.txt +0 -0
  177. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/glob.txt +0 -0
  178. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/grep.txt +0 -0
  179. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/memory.py +0 -0
  180. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/memory.txt +0 -0
  181. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/read_file.txt +0 -0
  182. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/skill_tool.py +0 -0
  183. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/skill_tool.txt +0 -0
  184. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/todo_read.py +0 -0
  185. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/todo_read.txt +0 -0
  186. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/todo_write.py +0 -0
  187. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/todo_write.txt +0 -0
  188. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_fetch.py +0 -0
  189. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_fetch.txt +0 -0
  190. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_search.py +0 -0
  191. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_search.txt +0 -0
  192. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
  193. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
  194. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk/tools/write_file.txt +0 -0
  195. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
  196. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk.egg-info/entry_points.txt +0 -0
  197. {txcode_sdk-1.0.0 → txcode_sdk-1.1.0}/src/txcode_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txcode-sdk
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: AI Agent SDK with built-in tools for Python projects
5
5
  Author: homecommunity
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "txcode-sdk"
7
- version = "1.0.0"
7
+ version = "1.1.0"
8
8
  description = "AI Agent SDK with built-in tools for Python projects"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -10,7 +10,6 @@
10
10
  环境变量:TXCODE_API_KEY(必填)/ TXCODE_BASE_URL / TXCODE_MODEL / TXCODE_WORK_DIR
11
11
  (CLI `txcode-sdk serve` 走 JSON 权威源装配,见 README;本示例直接读环境变量构造 client)"""
12
12
 
13
- import asyncio
14
13
  import os
15
14
  import sys
16
15
 
@@ -18,6 +17,7 @@ from txcode_sdk import Tool, ToolResult, TxCodeClient
18
17
  from txcode_sdk.server import TxCodeServer
19
18
  from txcode_sdk.server.provider_config import ProviderConfigManager
20
19
  from txcode_sdk.server.project_manager import ProjectManager
20
+ from txcode_sdk.utils.path_util import _get_event_loop
21
21
 
22
22
 
23
23
  def open_door(args, ctx):
@@ -32,18 +32,6 @@ def get_door_status(args, ctx):
32
32
  return ToolResult(success=True, output="closed")
33
33
 
34
34
 
35
- def _get_event_loop():
36
- """3.6/3.12 双版本兼容:已在运行 loop 则复用;否则新建(避免 3.12 弃用警告)。"""
37
- if hasattr(asyncio, "get_running_loop"):
38
- try:
39
- return asyncio.get_running_loop()
40
- except RuntimeError:
41
- pass
42
- loop = asyncio.new_event_loop()
43
- asyncio.set_event_loop(loop)
44
- return loop
45
-
46
-
47
35
  def main() -> int:
48
36
  api_key = os.environ.get("TXCODE_API_KEY", "").strip()
49
37
  if not api_key:
@@ -78,4 +78,4 @@ except Exception:
78
78
  ProjectManager = None
79
79
  JsonStore = None
80
80
 
81
- __version__ = "0.4.1"
81
+ __version__ = "1.1.0"
@@ -0,0 +1,391 @@
1
+ """BaseAgent 抽象基类(ReAct 主循环),Python 3.6 兼容。
2
+
3
+ 职责拆分(同模块文件):
4
+ - prompt_builder.PromptBuilderMixin —— 系统提示词构建
5
+ - message_utils.MessageUtilsMixin —— 消息构建与持久化
6
+ - step_utils.StepUtilsMixin —— 步骤记录 / 执行中通知
7
+ - compact_mixin.CompactMixin —— 上下文压缩
8
+ - hook_mixin.HookMixin —— 事件钩子
9
+ """
10
+
11
+ import asyncio
12
+ import json
13
+ import logging
14
+ import time
15
+ from abc import ABC, abstractmethod
16
+ from typing import Any, Callable, List, Optional
17
+
18
+ from ..provider.base import BaseProvider
19
+ from ..specs import SpecInjector
20
+ from ..types import (
21
+ ChatMessage,
22
+ ChatResult,
23
+ MediaFile,
24
+ ProviderResponse,
25
+ StepInfo,
26
+ TokenUsage,
27
+ ToolResultInfo,
28
+ )
29
+ from ..utils.log import _safe_summary, _summarize_arguments
30
+ from .compact_mixin import CompactMixin
31
+ from .hook_mixin import HookMixin
32
+ from .message_utils import MessageUtilsMixin
33
+ from .prompt_builder import PromptBuilderMixin
34
+ from .step_utils import StepUtilsMixin, _build_step_print_msg, _format_last_response
35
+ from .tool_registry import ToolRegistry
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+
40
+ class BaseAgent(
41
+ ABC,
42
+ PromptBuilderMixin,
43
+ MessageUtilsMixin,
44
+ StepUtilsMixin,
45
+ CompactMixin,
46
+ HookMixin,
47
+ ):
48
+ def __init__(
49
+ self,
50
+ provider: BaseProvider,
51
+ tool_registry: ToolRegistry,
52
+ session_manager: Any = None,
53
+ max_iterations: int = 50,
54
+ work_dir: str = "",
55
+ system_prompt: Optional[str] = None,
56
+ log_enabled: bool = False,
57
+ ):
58
+ self._provider = provider
59
+ self._registry = tool_registry
60
+ self._session_manager = session_manager
61
+ self._max_iterations = max_iterations
62
+ self._work_dir = work_dir or "."
63
+ self._system_prompt = system_prompt
64
+ self._log_enabled = log_enabled
65
+ self._round_count = 0
66
+ self._session_id: Optional[str] = None
67
+
68
+ @abstractmethod
69
+ def agent_type(self) -> str:
70
+ ...
71
+
72
+ @abstractmethod
73
+ def build_system_prompt(self, tools: List[dict]) -> str:
74
+ ...
75
+
76
+ async def run(
77
+ self,
78
+ user_message: str,
79
+ session_id: Optional[str] = None,
80
+ history: Optional[List[dict]] = None,
81
+ media_files: Optional[List[MediaFile]] = None,
82
+ on_step: Optional[Callable[[StepInfo], None]] = None,
83
+ on_compact: Optional[Callable[[dict], None]] = None,
84
+ abort_signal: Any = None,
85
+ ) -> ChatResult:
86
+ self._session_id = session_id
87
+ self._round_count = 0
88
+ tools = await self._registry.get_definitions()
89
+ system_prompt = self.build_system_prompt(tools)
90
+ self._base_messages: List[ChatMessage] = []
91
+ self._original_user_index: Optional[int] = None
92
+ self._injected_user_message: str = user_message
93
+
94
+ message_count = len(history) if history else 0
95
+
96
+ spec_injector = SpecInjector()
97
+ spec_injector.set_project_path(self._work_dir)
98
+
99
+ if spec_injector.should_inject(message_count):
100
+ injected = spec_injector.inject_into_message(user_message, self._work_dir)
101
+ self._injected_user_message = injected
102
+ else:
103
+ self._injected_user_message = user_message
104
+
105
+ if history:
106
+ for msg in history:
107
+ if msg.get("role") != "system":
108
+ self._base_messages.append(ChatMessage(
109
+ role=msg["role"],
110
+ content=msg.get("content", ""),
111
+ tool_call_id=msg.get("tool_call_id"),
112
+ tool_calls=msg.get("tool_calls"),
113
+ reasoning_content=msg.get("reasoning_content"),
114
+ ))
115
+
116
+ user_msg = self._build_user_message(self._injected_user_message, media_files)
117
+ self._base_messages.append(user_msg)
118
+ self._original_user_index = len(self._base_messages) - 1
119
+ self._save_message(session_id, "user", user_message, keep_context=True, is_original=True, media_files=media_files)
120
+
121
+ steps: List[StepInfo] = []
122
+ iteration = 0
123
+ final_answer = ""
124
+ total_usage = TokenUsage()
125
+ last_response: Optional[ProviderResponse] = None
126
+
127
+ while iteration < self._max_iterations:
128
+ if abort_signal and getattr(abort_signal, "aborted", False):
129
+ if self._log_enabled:
130
+ logger.info(
131
+ "agent run aborted | session=%s iteration=%d",
132
+ session_id, iteration,
133
+ )
134
+ return ChatResult(
135
+ answer="", steps=steps, session_id=session_id or "",
136
+ iterations=iteration, success=False, error="Aborted",
137
+ )
138
+
139
+ iteration += 1
140
+ self._round_count += 1
141
+ if self._round_count >= 10:
142
+ self._check_hooks("round")
143
+ self._round_count = 0
144
+
145
+ messages: List[ChatMessage] = [
146
+ ChatMessage(role="system", content=system_prompt),
147
+ *self._base_messages,
148
+ ]
149
+
150
+ if self._log_enabled:
151
+ logger.info(
152
+ "agent iteration started | session=%s iteration=%d action=call_ai",
153
+ session_id, iteration,
154
+ )
155
+
156
+ try:
157
+ response = await self._provider.chat(
158
+ messages, tools=tools, abort_signal=abort_signal,
159
+ log_context={
160
+ "session_id": session_id,
161
+ "agent_type": self.agent_type(),
162
+ "iteration": iteration,
163
+ "work_dir": self._work_dir,
164
+ } if self._log_enabled else None,
165
+ )
166
+ except Exception:
167
+ logger.exception(
168
+ "ai call failed | session=%s iteration=%d agent=%s",
169
+ session_id, iteration, self.agent_type(),
170
+ )
171
+ raise
172
+ last_response = response
173
+
174
+ if self._log_enabled:
175
+ logger.info(
176
+ "ai response received | session=%s iteration=%d finish_reason=%s tool_count=%d has_content=%s",
177
+ session_id, iteration, response.finish_reason,
178
+ len(response.tool_calls or []), "yes" if response.content else "no",
179
+ )
180
+ if response.usage:
181
+ logger.info(
182
+ "ai usage | session=%s iteration=%d prompt=%d completion=%d total=%d",
183
+ session_id, iteration,
184
+ response.usage.prompt_tokens,
185
+ response.usage.completion_tokens,
186
+ response.usage.total_tokens,
187
+ )
188
+ if response.content:
189
+ logger.debug(
190
+ "ai content summary | session=%s iteration=%d content=%s",
191
+ session_id, iteration, _safe_summary(response.content),
192
+ )
193
+
194
+ if response.usage:
195
+ total_usage.prompt_tokens = response.usage.prompt_tokens
196
+ total_usage.completion_tokens = response.usage.completion_tokens
197
+ total_usage.total_tokens = response.usage.total_tokens
198
+
199
+ if response.finish_reason == "stop" and response.content:
200
+ final_answer = response.content
201
+ self._save_message(session_id, "assistant", final_answer, keep_context=True)
202
+ break
203
+
204
+ if response.finish_reason == "tool_calls" and response.tool_calls:
205
+ tool_calls = ToolRegistry.parse_tool_calls(response.tool_calls)
206
+ results: List[ToolResultInfo] = []
207
+
208
+ for tc in tool_calls:
209
+ if self._log_enabled:
210
+ logger.info(
211
+ "tool execution started | session=%s iteration=%d tool=%s call_id=%s args=%s",
212
+ session_id, iteration, tc.name, tc.id,
213
+ _summarize_arguments(tc.arguments),
214
+ )
215
+ start_ts = time.time()
216
+ notify_task = None
217
+ if on_step:
218
+ notify_task = asyncio.ensure_future(
219
+ self._notify_executing_step(
220
+ on_step, response.reasoning, tool_calls, iteration
221
+ )
222
+ )
223
+ try:
224
+ result = await self._registry.execute(
225
+ tc.name, tc.arguments,
226
+ self._build_tool_context(session_id or ""),
227
+ )
228
+ except Exception:
229
+ logger.exception(
230
+ "tool execution failed | session=%s iteration=%d tool=%s call_id=%s",
231
+ session_id, iteration, tc.name, tc.id,
232
+ )
233
+ raise
234
+ finally:
235
+ if notify_task is not None:
236
+ notify_task.cancel()
237
+ elapsed_ms = int((time.time() - start_ts) * 1000)
238
+ results.append(ToolResultInfo(
239
+ name=tc.name,
240
+ success=result.success,
241
+ output=result.output,
242
+ error=result.error,
243
+ ))
244
+
245
+ if self._log_enabled:
246
+ logger.info(
247
+ "tool execution completed | session=%s iteration=%d tool=%s success=%s elapsed_ms=%d",
248
+ session_id, iteration, tc.name, result.success, elapsed_ms,
249
+ )
250
+ if result.success:
251
+ logger.debug(
252
+ "tool output summary | session=%s iteration=%d tool=%s output=%s",
253
+ session_id, iteration, tc.name, _safe_summary(result.output),
254
+ )
255
+ if not result.success:
256
+ logger.warning(
257
+ "tool execution error | session=%s iteration=%d tool=%s call_id=%s error=%s",
258
+ session_id, iteration, tc.name, tc.id,
259
+ _safe_summary(result.error or ""),
260
+ )
261
+
262
+ step = StepInfo(
263
+ reasoning=response.reasoning,
264
+ tool_calls=tool_calls,
265
+ results=results,
266
+ iteration=iteration,
267
+ usage=response.usage,
268
+ )
269
+ step.printMsg = _build_step_print_msg(step)
270
+ steps.append(step)
271
+
272
+ if on_step:
273
+ on_step(step)
274
+
275
+ for i, tc in enumerate(tool_calls):
276
+ res = results[i]
277
+ # assistant message with tool_calls
278
+ assistant_msg = ChatMessage(
279
+ role="assistant",
280
+ content="",
281
+ tool_calls=[{
282
+ "id": tc.id,
283
+ "type": "function",
284
+ "function": {"name": tc.name, "arguments": json.dumps(tc.arguments)},
285
+ }],
286
+ reasoning_content=response.reasoning,
287
+ )
288
+ self._base_messages.append(assistant_msg)
289
+ self._save_message(
290
+ session_id, "assistant", "",
291
+ keep_context=True,
292
+ tool_calls=assistant_msg.tool_calls,
293
+ reasoning=response.reasoning,
294
+ )
295
+
296
+ # tool message
297
+ tool_msg = ChatMessage(
298
+ role="tool",
299
+ content=res.output if res.success else "Error: %s" % res.error,
300
+ tool_call_id=tc.id,
301
+ )
302
+ self._base_messages.append(tool_msg)
303
+ self._save_message(
304
+ session_id, "tool", tool_msg.content,
305
+ keep_context=False, tool_call_id=tc.id,
306
+ )
307
+
308
+ new_messages_start_index = len(self._base_messages) - 2 * len(tool_calls)
309
+ await self._check_and_compact(
310
+ session_id, on_compact, self._base_messages,
311
+ total_usage, new_messages_start_index,
312
+ )
313
+ continue
314
+
315
+ if response.content:
316
+ final_answer = response.content
317
+ break
318
+
319
+ break
320
+
321
+ self._check_hooks("end")
322
+
323
+ aborted = bool(abort_signal and getattr(abort_signal, "aborted", False))
324
+ if self._log_enabled:
325
+ if final_answer != "":
326
+ logger.info(
327
+ "agent run finished | session=%s iterations=%d status=success",
328
+ session_id, iteration,
329
+ )
330
+ elif aborted:
331
+ logger.info(
332
+ "agent run finished | session=%s iterations=%d status=aborted",
333
+ session_id, iteration,
334
+ )
335
+ elif iteration >= self._max_iterations:
336
+ logger.info(
337
+ "agent run finished | session=%s iterations=%d status=max_iterations",
338
+ session_id, iteration,
339
+ )
340
+ else:
341
+ logger.info(
342
+ "agent run finished | session=%s iterations=%d status=failed",
343
+ session_id, iteration,
344
+ )
345
+
346
+ err: Optional[str] = None
347
+ answer = final_answer
348
+ if final_answer == "":
349
+ if iteration >= self._max_iterations:
350
+ header = "已达到最大循环次数 %d 次,任务未完成" % self._max_iterations
351
+ err = "Max iterations reached (%d)" % self._max_iterations
352
+ elif last_response is not None:
353
+ fr = last_response.finish_reason or ""
354
+ if fr == "length":
355
+ header = "AI 响应被截断(finish_reason=length)"
356
+ err = "Response truncated (length)"
357
+ elif fr and fr not in ("stop", "tool_calls"):
358
+ header = "AI 返回异常 finish_reason=%s" % fr
359
+ err = "Unexpected finish_reason: %s" % fr
360
+ elif not last_response.content and not last_response.tool_calls:
361
+ header = "AI 返回空响应"
362
+ err = "Empty response from provider"
363
+ else:
364
+ header = "Unable to complete task"
365
+ err = "Unknown"
366
+ else:
367
+ header = "Unable to complete task"
368
+ err = "Unknown"
369
+
370
+ if last_response is not None:
371
+ answer = header + "\n" + _format_last_response(last_response)
372
+ else:
373
+ answer = header
374
+
375
+ logger.warning(
376
+ "agent run failed | session=%s iter=%d | %s",
377
+ session_id, iteration, err,
378
+ )
379
+ if last_response is not None:
380
+ logger.warning("last response: %s", _format_last_response(last_response))
381
+
382
+ success = final_answer != ""
383
+ return ChatResult(
384
+ answer=answer,
385
+ steps=steps,
386
+ session_id=session_id or "",
387
+ iterations=iteration,
388
+ success=success,
389
+ error=err,
390
+ usage=total_usage,
391
+ )
@@ -3,22 +3,22 @@
3
3
  from typing import List
4
4
 
5
5
  from ..base_agent import BaseAgent
6
- from ..tool_registry import ToolRegistry
6
+ from ..factory import build_agent_args
7
7
  from .agent_tool import CHAT_TOOLS
8
8
 
9
9
 
10
10
  class ChatAgent(BaseAgent):
11
11
  def __init__(self, provider, extra_tools=None, session_manager=None, max_iterations=50, work_dir="", system_prompt=None, log_enabled=False):
12
- registry = ToolRegistry(allowed_tools=CHAT_TOOLS, extra_tools=extra_tools)
13
- super().__init__(
12
+ super().__init__(**build_agent_args(
14
13
  provider=provider,
15
- tool_registry=registry,
14
+ extra_tools=extra_tools,
16
15
  session_manager=session_manager,
17
16
  max_iterations=max_iterations,
18
17
  work_dir=work_dir,
19
18
  system_prompt=system_prompt,
20
19
  log_enabled=log_enabled,
21
- )
20
+ allowed_tools=CHAT_TOOLS,
21
+ ))
22
22
 
23
23
  def agent_type(self) -> str:
24
24
  return "chat"
@@ -3,22 +3,23 @@
3
3
  from typing import List
4
4
 
5
5
  from ..base_agent import BaseAgent
6
- from ..tool_registry import ToolRegistry
6
+ from ..factory import build_agent_args
7
7
  from .agent_tool import CODE_TOOLS
8
8
 
9
9
 
10
10
  class CodeAgent(BaseAgent):
11
11
  def __init__(self, provider, extra_tools=None, session_manager=None, max_iterations=50, work_dir="", system_prompt=None, log_enabled=False):
12
- registry = ToolRegistry(allowed_tools=CODE_TOOLS, extra_tools=extra_tools, verbose_error=True)
13
- super().__init__(
12
+ super().__init__(**build_agent_args(
14
13
  provider=provider,
15
- tool_registry=registry,
14
+ extra_tools=extra_tools,
16
15
  session_manager=session_manager,
17
16
  max_iterations=max_iterations,
18
17
  work_dir=work_dir,
19
18
  system_prompt=system_prompt,
20
19
  log_enabled=log_enabled,
21
- )
20
+ allowed_tools=CODE_TOOLS,
21
+ verbose_error=True,
22
+ ))
22
23
 
23
24
  def agent_type(self) -> str:
24
25
  return "code"
@@ -3,21 +3,21 @@
3
3
  from typing import List
4
4
 
5
5
  from ..base_agent import BaseAgent
6
- from ..tool_registry import ToolRegistry
6
+ from ..factory import build_agent_args
7
7
 
8
8
 
9
9
  class CommonAgent(BaseAgent):
10
10
  def __init__(self, provider, extra_tools=None, session_manager=None, max_iterations=50, work_dir="", system_prompt=None, log_enabled=False):
11
- registry = ToolRegistry(allowed_tools=None, extra_tools=extra_tools)
12
- super().__init__(
11
+ super().__init__(**build_agent_args(
13
12
  provider=provider,
14
- tool_registry=registry,
13
+ extra_tools=extra_tools,
15
14
  session_manager=session_manager,
16
15
  max_iterations=max_iterations,
17
16
  work_dir=work_dir,
18
17
  system_prompt=system_prompt,
19
18
  log_enabled=log_enabled,
20
- )
19
+ allowed_tools=None,
20
+ ))
21
21
 
22
22
  def agent_type(self) -> str:
23
23
  return "common"
@@ -0,0 +1,91 @@
1
+ """上下文压缩(Python 3.6 兼容)。
2
+
3
+ 从 base_agent.py 拆出:_check_and_compact —— 基于 prompt tokens 阈值
4
+ 触发压缩,压缩后重建 base_messages(注入用户消息 + 总结历史 + 当前工具结果)。
5
+ """
6
+
7
+ import logging
8
+ from typing import Any, Callable, List, Optional
9
+
10
+ from ..types import ChatMessage, TokenUsage
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ class CompactMixin:
16
+ """上下文压缩:客户端注入 ContextCompressor,超阈值时自动压缩。"""
17
+
18
+ def set_compressor(self, compressor: Any):
19
+ """注入客户端的 ContextCompressor,确保 _check_and_compact 使用同一实例。"""
20
+ self._compressor = compressor
21
+
22
+ async def _check_and_compact(
23
+ self,
24
+ session_id: Optional[str],
25
+ on_compact: Optional[Callable[[dict], None]],
26
+ base_messages: Optional[List[ChatMessage]] = None,
27
+ total_usage: Optional[TokenUsage] = None,
28
+ new_messages_start_index: int = 0,
29
+ ):
30
+ if not session_id or not self._session_manager:
31
+ return
32
+
33
+ if base_messages is None:
34
+ base_messages = getattr(self, "_base_messages", [])
35
+
36
+ compressor = getattr(self, "_compressor", None)
37
+ if compressor is None:
38
+ from ..compact.compressor import ContextCompressor
39
+ compressor = ContextCompressor(
40
+ max_tokens=150_000,
41
+ provider=self._provider,
42
+ session_manager=self._session_manager,
43
+ )
44
+ self._compressor = compressor
45
+
46
+ prompt_tokens = total_usage.prompt_tokens if total_usage else 0
47
+ check = compressor.check_needs_compact(prompt_tokens=prompt_tokens)
48
+ if not check.needed:
49
+ return
50
+
51
+ self._check_hooks("before_compact")
52
+ self._round_count = 0
53
+
54
+ current_tool_results: List[ChatMessage] = [
55
+ m for m in base_messages[new_messages_start_index:]
56
+ if m.role == "tool" or (m.role == "assistant" and m.tool_calls)
57
+ ]
58
+
59
+ try:
60
+ result = await compressor.compact(session_id)
61
+
62
+ if result.success:
63
+ injected = getattr(self, "_injected_user_message", "")
64
+ new_base: List[ChatMessage] = []
65
+ if injected:
66
+ new_base.append(ChatMessage(role="user", content=injected))
67
+ self._original_user_index = 0 if new_base else None
68
+
69
+ session = self._session_manager.get(session_id)
70
+ summary_index = (session or {}).get("summary_message_index")
71
+ summary_msgs = self._session_manager.get_messages_for_ai(
72
+ session_id, summary_index=summary_index
73
+ )
74
+ for m in summary_msgs:
75
+ if m.get("role") == "system":
76
+ continue
77
+ new_base.append(self._history_to_chat_message(m))
78
+
79
+ new_base.extend(current_tool_results)
80
+ base_messages.clear()
81
+ base_messages.extend(new_base)
82
+ self._base_messages = base_messages
83
+
84
+ if on_compact:
85
+ on_compact({
86
+ "beforeTokens": check.current_tokens,
87
+ "afterTokens": result.tokens_after,
88
+ "summary": result.summary,
89
+ })
90
+ except Exception as e:
91
+ logger.warning("[AutoCompact] Error: %s", e)
@@ -3,22 +3,23 @@
3
3
  from typing import List
4
4
 
5
5
  from ..base_agent import BaseAgent
6
- from ..tool_registry import ToolRegistry
6
+ from ..factory import build_agent_args
7
7
  from .agent_tool import DESIGN_TOOLS
8
8
 
9
9
 
10
10
  class DesignAgent(BaseAgent):
11
11
  def __init__(self, provider, extra_tools=None, session_manager=None, max_iterations=50, work_dir="", system_prompt=None, log_enabled=False):
12
- registry = ToolRegistry(allowed_tools=DESIGN_TOOLS, extra_tools=extra_tools, verbose_error=True)
13
- super().__init__(
12
+ super().__init__(**build_agent_args(
14
13
  provider=provider,
15
- tool_registry=registry,
14
+ extra_tools=extra_tools,
16
15
  session_manager=session_manager,
17
16
  max_iterations=max_iterations,
18
17
  work_dir=work_dir,
19
18
  system_prompt=system_prompt,
20
19
  log_enabled=log_enabled,
21
- )
20
+ allowed_tools=DESIGN_TOOLS,
21
+ verbose_error=True,
22
+ ))
22
23
 
23
24
  def agent_type(self) -> str:
24
25
  return "design"