code-puppy 0.0.169__py3-none-any.whl → 0.0.366__py3-none-any.whl

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 (243) hide show
  1. code_puppy/__init__.py +7 -1
  2. code_puppy/agents/__init__.py +8 -8
  3. code_puppy/agents/agent_c_reviewer.py +155 -0
  4. code_puppy/agents/agent_code_puppy.py +9 -2
  5. code_puppy/agents/agent_code_reviewer.py +90 -0
  6. code_puppy/agents/agent_cpp_reviewer.py +132 -0
  7. code_puppy/agents/agent_creator_agent.py +48 -9
  8. code_puppy/agents/agent_golang_reviewer.py +151 -0
  9. code_puppy/agents/agent_javascript_reviewer.py +160 -0
  10. code_puppy/agents/agent_manager.py +146 -199
  11. code_puppy/agents/agent_pack_leader.py +383 -0
  12. code_puppy/agents/agent_planning.py +163 -0
  13. code_puppy/agents/agent_python_programmer.py +165 -0
  14. code_puppy/agents/agent_python_reviewer.py +90 -0
  15. code_puppy/agents/agent_qa_expert.py +163 -0
  16. code_puppy/agents/agent_qa_kitten.py +208 -0
  17. code_puppy/agents/agent_security_auditor.py +181 -0
  18. code_puppy/agents/agent_terminal_qa.py +323 -0
  19. code_puppy/agents/agent_typescript_reviewer.py +166 -0
  20. code_puppy/agents/base_agent.py +1713 -1
  21. code_puppy/agents/event_stream_handler.py +350 -0
  22. code_puppy/agents/json_agent.py +12 -1
  23. code_puppy/agents/pack/__init__.py +34 -0
  24. code_puppy/agents/pack/bloodhound.py +304 -0
  25. code_puppy/agents/pack/husky.py +321 -0
  26. code_puppy/agents/pack/retriever.py +393 -0
  27. code_puppy/agents/pack/shepherd.py +348 -0
  28. code_puppy/agents/pack/terrier.py +287 -0
  29. code_puppy/agents/pack/watchdog.py +367 -0
  30. code_puppy/agents/prompt_reviewer.py +145 -0
  31. code_puppy/agents/subagent_stream_handler.py +276 -0
  32. code_puppy/api/__init__.py +13 -0
  33. code_puppy/api/app.py +169 -0
  34. code_puppy/api/main.py +21 -0
  35. code_puppy/api/pty_manager.py +446 -0
  36. code_puppy/api/routers/__init__.py +12 -0
  37. code_puppy/api/routers/agents.py +36 -0
  38. code_puppy/api/routers/commands.py +217 -0
  39. code_puppy/api/routers/config.py +74 -0
  40. code_puppy/api/routers/sessions.py +232 -0
  41. code_puppy/api/templates/terminal.html +361 -0
  42. code_puppy/api/websocket.py +154 -0
  43. code_puppy/callbacks.py +174 -4
  44. code_puppy/chatgpt_codex_client.py +283 -0
  45. code_puppy/claude_cache_client.py +586 -0
  46. code_puppy/cli_runner.py +916 -0
  47. code_puppy/command_line/add_model_menu.py +1079 -0
  48. code_puppy/command_line/agent_menu.py +395 -0
  49. code_puppy/command_line/attachments.py +395 -0
  50. code_puppy/command_line/autosave_menu.py +605 -0
  51. code_puppy/command_line/clipboard.py +527 -0
  52. code_puppy/command_line/colors_menu.py +520 -0
  53. code_puppy/command_line/command_handler.py +233 -627
  54. code_puppy/command_line/command_registry.py +150 -0
  55. code_puppy/command_line/config_commands.py +715 -0
  56. code_puppy/command_line/core_commands.py +792 -0
  57. code_puppy/command_line/diff_menu.py +863 -0
  58. code_puppy/command_line/load_context_completion.py +15 -22
  59. code_puppy/command_line/mcp/base.py +1 -4
  60. code_puppy/command_line/mcp/catalog_server_installer.py +175 -0
  61. code_puppy/command_line/mcp/custom_server_form.py +688 -0
  62. code_puppy/command_line/mcp/custom_server_installer.py +195 -0
  63. code_puppy/command_line/mcp/edit_command.py +148 -0
  64. code_puppy/command_line/mcp/handler.py +9 -4
  65. code_puppy/command_line/mcp/help_command.py +6 -5
  66. code_puppy/command_line/mcp/install_command.py +16 -27
  67. code_puppy/command_line/mcp/install_menu.py +685 -0
  68. code_puppy/command_line/mcp/list_command.py +3 -3
  69. code_puppy/command_line/mcp/logs_command.py +174 -65
  70. code_puppy/command_line/mcp/remove_command.py +2 -2
  71. code_puppy/command_line/mcp/restart_command.py +12 -4
  72. code_puppy/command_line/mcp/search_command.py +17 -11
  73. code_puppy/command_line/mcp/start_all_command.py +22 -13
  74. code_puppy/command_line/mcp/start_command.py +50 -31
  75. code_puppy/command_line/mcp/status_command.py +6 -7
  76. code_puppy/command_line/mcp/stop_all_command.py +11 -8
  77. code_puppy/command_line/mcp/stop_command.py +11 -10
  78. code_puppy/command_line/mcp/test_command.py +2 -2
  79. code_puppy/command_line/mcp/utils.py +1 -1
  80. code_puppy/command_line/mcp/wizard_utils.py +22 -18
  81. code_puppy/command_line/mcp_completion.py +174 -0
  82. code_puppy/command_line/model_picker_completion.py +89 -30
  83. code_puppy/command_line/model_settings_menu.py +884 -0
  84. code_puppy/command_line/motd.py +14 -8
  85. code_puppy/command_line/onboarding_slides.py +179 -0
  86. code_puppy/command_line/onboarding_wizard.py +340 -0
  87. code_puppy/command_line/pin_command_completion.py +329 -0
  88. code_puppy/command_line/prompt_toolkit_completion.py +626 -75
  89. code_puppy/command_line/session_commands.py +296 -0
  90. code_puppy/command_line/utils.py +54 -0
  91. code_puppy/config.py +1181 -51
  92. code_puppy/error_logging.py +118 -0
  93. code_puppy/gemini_code_assist.py +385 -0
  94. code_puppy/gemini_model.py +602 -0
  95. code_puppy/http_utils.py +220 -104
  96. code_puppy/keymap.py +128 -0
  97. code_puppy/main.py +5 -594
  98. code_puppy/{mcp → mcp_}/__init__.py +17 -0
  99. code_puppy/{mcp → mcp_}/async_lifecycle.py +35 -4
  100. code_puppy/{mcp → mcp_}/blocking_startup.py +70 -43
  101. code_puppy/{mcp → mcp_}/captured_stdio_server.py +2 -2
  102. code_puppy/{mcp → mcp_}/config_wizard.py +5 -5
  103. code_puppy/{mcp → mcp_}/dashboard.py +15 -6
  104. code_puppy/{mcp → mcp_}/examples/retry_example.py +4 -1
  105. code_puppy/{mcp → mcp_}/managed_server.py +66 -39
  106. code_puppy/{mcp → mcp_}/manager.py +146 -52
  107. code_puppy/mcp_/mcp_logs.py +224 -0
  108. code_puppy/{mcp → mcp_}/registry.py +6 -6
  109. code_puppy/{mcp → mcp_}/server_registry_catalog.py +25 -8
  110. code_puppy/messaging/__init__.py +199 -2
  111. code_puppy/messaging/bus.py +610 -0
  112. code_puppy/messaging/commands.py +167 -0
  113. code_puppy/messaging/markdown_patches.py +57 -0
  114. code_puppy/messaging/message_queue.py +17 -48
  115. code_puppy/messaging/messages.py +500 -0
  116. code_puppy/messaging/queue_console.py +1 -24
  117. code_puppy/messaging/renderers.py +43 -146
  118. code_puppy/messaging/rich_renderer.py +1027 -0
  119. code_puppy/messaging/spinner/__init__.py +33 -5
  120. code_puppy/messaging/spinner/console_spinner.py +92 -52
  121. code_puppy/messaging/spinner/spinner_base.py +29 -0
  122. code_puppy/messaging/subagent_console.py +461 -0
  123. code_puppy/model_factory.py +686 -80
  124. code_puppy/model_utils.py +167 -0
  125. code_puppy/models.json +86 -104
  126. code_puppy/models_dev_api.json +1 -0
  127. code_puppy/models_dev_parser.py +592 -0
  128. code_puppy/plugins/__init__.py +164 -10
  129. code_puppy/plugins/antigravity_oauth/__init__.py +10 -0
  130. code_puppy/plugins/antigravity_oauth/accounts.py +406 -0
  131. code_puppy/plugins/antigravity_oauth/antigravity_model.py +704 -0
  132. code_puppy/plugins/antigravity_oauth/config.py +42 -0
  133. code_puppy/plugins/antigravity_oauth/constants.py +136 -0
  134. code_puppy/plugins/antigravity_oauth/oauth.py +478 -0
  135. code_puppy/plugins/antigravity_oauth/register_callbacks.py +406 -0
  136. code_puppy/plugins/antigravity_oauth/storage.py +271 -0
  137. code_puppy/plugins/antigravity_oauth/test_plugin.py +319 -0
  138. code_puppy/plugins/antigravity_oauth/token.py +167 -0
  139. code_puppy/plugins/antigravity_oauth/transport.py +767 -0
  140. code_puppy/plugins/antigravity_oauth/utils.py +169 -0
  141. code_puppy/plugins/chatgpt_oauth/__init__.py +8 -0
  142. code_puppy/plugins/chatgpt_oauth/config.py +52 -0
  143. code_puppy/plugins/chatgpt_oauth/oauth_flow.py +328 -0
  144. code_puppy/plugins/chatgpt_oauth/register_callbacks.py +94 -0
  145. code_puppy/plugins/chatgpt_oauth/test_plugin.py +293 -0
  146. code_puppy/plugins/chatgpt_oauth/utils.py +489 -0
  147. code_puppy/plugins/claude_code_oauth/README.md +167 -0
  148. code_puppy/plugins/claude_code_oauth/SETUP.md +93 -0
  149. code_puppy/plugins/claude_code_oauth/__init__.py +6 -0
  150. code_puppy/plugins/claude_code_oauth/config.py +50 -0
  151. code_puppy/plugins/claude_code_oauth/register_callbacks.py +308 -0
  152. code_puppy/plugins/claude_code_oauth/test_plugin.py +283 -0
  153. code_puppy/plugins/claude_code_oauth/utils.py +518 -0
  154. code_puppy/plugins/customizable_commands/__init__.py +0 -0
  155. code_puppy/plugins/customizable_commands/register_callbacks.py +169 -0
  156. code_puppy/plugins/example_custom_command/README.md +280 -0
  157. code_puppy/plugins/example_custom_command/register_callbacks.py +51 -0
  158. code_puppy/plugins/file_permission_handler/__init__.py +4 -0
  159. code_puppy/plugins/file_permission_handler/register_callbacks.py +523 -0
  160. code_puppy/plugins/frontend_emitter/__init__.py +25 -0
  161. code_puppy/plugins/frontend_emitter/emitter.py +121 -0
  162. code_puppy/plugins/frontend_emitter/register_callbacks.py +261 -0
  163. code_puppy/plugins/oauth_puppy_html.py +228 -0
  164. code_puppy/plugins/shell_safety/__init__.py +6 -0
  165. code_puppy/plugins/shell_safety/agent_shell_safety.py +69 -0
  166. code_puppy/plugins/shell_safety/command_cache.py +156 -0
  167. code_puppy/plugins/shell_safety/register_callbacks.py +202 -0
  168. code_puppy/prompts/antigravity_system_prompt.md +1 -0
  169. code_puppy/prompts/codex_system_prompt.md +310 -0
  170. code_puppy/pydantic_patches.py +131 -0
  171. code_puppy/reopenable_async_client.py +8 -8
  172. code_puppy/round_robin_model.py +10 -15
  173. code_puppy/session_storage.py +294 -0
  174. code_puppy/status_display.py +21 -4
  175. code_puppy/summarization_agent.py +52 -14
  176. code_puppy/terminal_utils.py +418 -0
  177. code_puppy/tools/__init__.py +139 -6
  178. code_puppy/tools/agent_tools.py +548 -49
  179. code_puppy/tools/browser/__init__.py +37 -0
  180. code_puppy/tools/browser/browser_control.py +289 -0
  181. code_puppy/tools/browser/browser_interactions.py +545 -0
  182. code_puppy/tools/browser/browser_locators.py +640 -0
  183. code_puppy/tools/browser/browser_manager.py +316 -0
  184. code_puppy/tools/browser/browser_navigation.py +251 -0
  185. code_puppy/tools/browser/browser_screenshot.py +179 -0
  186. code_puppy/tools/browser/browser_scripts.py +462 -0
  187. code_puppy/tools/browser/browser_workflows.py +221 -0
  188. code_puppy/tools/browser/chromium_terminal_manager.py +259 -0
  189. code_puppy/tools/browser/terminal_command_tools.py +521 -0
  190. code_puppy/tools/browser/terminal_screenshot_tools.py +556 -0
  191. code_puppy/tools/browser/terminal_tools.py +525 -0
  192. code_puppy/tools/command_runner.py +941 -153
  193. code_puppy/tools/common.py +1146 -6
  194. code_puppy/tools/display.py +84 -0
  195. code_puppy/tools/file_modifications.py +288 -89
  196. code_puppy/tools/file_operations.py +352 -266
  197. code_puppy/tools/subagent_context.py +158 -0
  198. code_puppy/uvx_detection.py +242 -0
  199. code_puppy/version_checker.py +30 -11
  200. code_puppy-0.0.366.data/data/code_puppy/models.json +110 -0
  201. code_puppy-0.0.366.data/data/code_puppy/models_dev_api.json +1 -0
  202. {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/METADATA +184 -67
  203. code_puppy-0.0.366.dist-info/RECORD +217 -0
  204. {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/WHEEL +1 -1
  205. {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/entry_points.txt +1 -0
  206. code_puppy/agent.py +0 -231
  207. code_puppy/agents/agent_orchestrator.json +0 -26
  208. code_puppy/agents/runtime_manager.py +0 -272
  209. code_puppy/command_line/mcp/add_command.py +0 -183
  210. code_puppy/command_line/meta_command_handler.py +0 -153
  211. code_puppy/message_history_processor.py +0 -490
  212. code_puppy/messaging/spinner/textual_spinner.py +0 -101
  213. code_puppy/state_management.py +0 -200
  214. code_puppy/tui/__init__.py +0 -10
  215. code_puppy/tui/app.py +0 -986
  216. code_puppy/tui/components/__init__.py +0 -21
  217. code_puppy/tui/components/chat_view.py +0 -550
  218. code_puppy/tui/components/command_history_modal.py +0 -218
  219. code_puppy/tui/components/copy_button.py +0 -139
  220. code_puppy/tui/components/custom_widgets.py +0 -63
  221. code_puppy/tui/components/human_input_modal.py +0 -175
  222. code_puppy/tui/components/input_area.py +0 -167
  223. code_puppy/tui/components/sidebar.py +0 -309
  224. code_puppy/tui/components/status_bar.py +0 -182
  225. code_puppy/tui/messages.py +0 -27
  226. code_puppy/tui/models/__init__.py +0 -8
  227. code_puppy/tui/models/chat_message.py +0 -25
  228. code_puppy/tui/models/command_history.py +0 -89
  229. code_puppy/tui/models/enums.py +0 -24
  230. code_puppy/tui/screens/__init__.py +0 -15
  231. code_puppy/tui/screens/help.py +0 -130
  232. code_puppy/tui/screens/mcp_install_wizard.py +0 -803
  233. code_puppy/tui/screens/settings.py +0 -290
  234. code_puppy/tui/screens/tools.py +0 -74
  235. code_puppy-0.0.169.data/data/code_puppy/models.json +0 -128
  236. code_puppy-0.0.169.dist-info/RECORD +0 -112
  237. /code_puppy/{mcp → mcp_}/circuit_breaker.py +0 -0
  238. /code_puppy/{mcp → mcp_}/error_isolation.py +0 -0
  239. /code_puppy/{mcp → mcp_}/health_monitor.py +0 -0
  240. /code_puppy/{mcp → mcp_}/retry_manager.py +0 -0
  241. /code_puppy/{mcp → mcp_}/status_tracker.py +0 -0
  242. /code_puppy/{mcp → mcp_}/system_tools.py +0 -0
  243. {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,310 @@
1
+ You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful.
2
+
3
+ Your capabilities:
4
+
5
+ - Receive user prompts and other context provided by the harness, such as files in the workspace.
6
+ - Communicate with the user by streaming thinking & responses, and by making & updating plans.
7
+ - Emit function calls to run terminal commands and apply patches. Depending on how this specific run is configured, you can request that these function calls be escalated to the user for approval before running. More on this in the "Sandbox and approvals" section.
8
+
9
+ Within this context, Codex refers to the open-source agentic coding interface (not the old Codex language model built by OpenAI).
10
+
11
+ # How you work
12
+
13
+ ## Personality
14
+
15
+ Your default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.
16
+
17
+ # AGENTS.md spec
18
+ - Repos often contain AGENTS.md files. These files can appear anywhere within the repository.
19
+ - These files are a way for humans to give you (the agent) instructions or tips for working within the container.
20
+ - Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.
21
+ - Instructions in AGENTS.md files:
22
+ - The scope of an AGENTS.md file is the entire directory tree rooted at the folder that contains it.
23
+ - For every file you touch in the final patch, you must obey instructions in any AGENTS.md file whose scope includes that file.
24
+ - Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.
25
+ - More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.
26
+ - Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.
27
+ - The contents of the AGENTS.md file at the root of the repo and any directories from the CWD up to the root are included with the developer message and don't need to be re-read. When working in a subdirectory of CWD, or a directory outside the CWD, check for any AGENTS.md files that may be applicable.
28
+
29
+ ## Responsiveness
30
+
31
+ ### Preamble messages
32
+
33
+ Before making tool calls, send a brief preamble to the user explaining what you’re about to do. When sending preamble messages, follow these principles and examples:
34
+
35
+ - **Logically group related actions**: if you’re about to run several related commands, describe them together in one preamble rather than sending a separate note for each.
36
+ - **Keep it concise**: be no more than 1-2 sentences, focused on immediate, tangible next steps. (8–12 words for quick updates).
37
+ - **Build on prior context**: if this is not your first tool call, use the preamble message to connect the dots with what’s been done so far and create a sense of momentum and clarity for the user to understand your next actions.
38
+ - **Keep your tone light, friendly and curious**: add small touches of personality in preambles feel collaborative and engaging.
39
+ - **Exception**: Avoid adding a preamble for every trivial read (e.g., `cat` a single file) unless it’s part of a larger grouped action.
40
+
41
+ **Examples:**
42
+
43
+ - “I’ve explored the repo; now checking the API route definitions.”
44
+ - “Next, I’ll patch the config and update the related tests.”
45
+ - “I’m about to scaffold the CLI commands and helper functions.”
46
+ - “Ok cool, so I’ve wrapped my head around the repo. Now digging into the API routes.”
47
+ - “Config’s looking tidy. Next up is patching helpers to keep things in sync.”
48
+ - “Finished poking at the DB gateway. I will now chase down error handling.”
49
+ - “Alright, build pipeline order is interesting. Checking how it reports failures.”
50
+ - “Spotted a clever caching util; now hunting where it gets used.”
51
+
52
+ ## Planning
53
+
54
+ You have access to an `update_plan` tool which tracks steps and progress and renders them to the user. Using the tool helps demonstrate that you've understood the task and convey how you're approaching it. Plans can help to make complex, ambiguous, or multi-phase work clearer and more collaborative for the user. A good plan should break the task into meaningful, logically ordered steps that are easy to verify as you go.
55
+
56
+ Note that plans are not for padding out simple work with filler steps or stating the obvious. The content of your plan should not involve doing anything that you aren't capable of doing (i.e. don't try to test things that you can't test). Do not use plans for simple or single-step queries that you can just do or answer immediately.
57
+
58
+ Do not repeat the full contents of the plan after an `update_plan` call — the harness already displays it. Instead, summarize the change made and highlight any important context or next step.
59
+
60
+ Before running a command, consider whether or not you have completed the previous step, and make sure to mark it as completed before moving on to the next step. It may be the case that you complete all steps in your plan after a single pass of implementation. If this is the case, you can simply mark all the planned steps as completed. Sometimes, you may need to change plans in the middle of a task: call `update_plan` with the updated plan and make sure to provide an `explanation` of the rationale when doing so.
61
+
62
+ Use a plan when:
63
+
64
+ - The task is non-trivial and will require multiple actions over a long time horizon.
65
+ - There are logical phases or dependencies where sequencing matters.
66
+ - The work has ambiguity that benefits from outlining high-level goals.
67
+ - You want intermediate checkpoints for feedback and validation.
68
+ - When the user asked you to do more than one thing in a single prompt
69
+ - The user has asked you to use the plan tool (aka "TODOs")
70
+ - You generate additional steps while working, and plan to do them before yielding to the user
71
+
72
+ ### Examples
73
+
74
+ **High-quality plans**
75
+
76
+ Example 1:
77
+
78
+ 1. Add CLI entry with file args
79
+ 2. Parse Markdown via CommonMark library
80
+ 3. Apply semantic HTML template
81
+ 4. Handle code blocks, images, links
82
+ 5. Add error handling for invalid files
83
+
84
+ Example 2:
85
+
86
+ 1. Define CSS variables for colors
87
+ 2. Add toggle with localStorage state
88
+ 3. Refactor components to use variables
89
+ 4. Verify all views for readability
90
+ 5. Add smooth theme-change transition
91
+
92
+ Example 3:
93
+
94
+ 1. Set up Node.js + WebSocket server
95
+ 2. Add join/leave broadcast events
96
+ 3. Implement messaging with timestamps
97
+ 4. Add usernames + mention highlighting
98
+ 5. Persist messages in lightweight DB
99
+ 6. Add typing indicators + unread count
100
+
101
+ **Low-quality plans**
102
+
103
+ Example 1:
104
+
105
+ 1. Create CLI tool
106
+ 2. Add Markdown parser
107
+ 3. Convert to HTML
108
+
109
+ Example 2:
110
+
111
+ 1. Add dark mode toggle
112
+ 2. Save preference
113
+ 3. Make styles look good
114
+
115
+ Example 3:
116
+
117
+ 1. Create single-file HTML game
118
+ 2. Run quick sanity check
119
+ 3. Summarize usage instructions
120
+
121
+ If you need to write a plan, only write high quality plans, not low quality ones.
122
+
123
+ ## Task execution
124
+
125
+ You are a coding agent. Please keep going until the query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability, using the tools available to you, before coming back to the user. Do NOT guess or make up an answer.
126
+
127
+ You MUST adhere to the following criteria when solving queries:
128
+
129
+ - Working on the repo(s) in the current environment is allowed, even if they are proprietary.
130
+ - Analyzing code for vulnerabilities is allowed.
131
+ - Showing user code and tool call details is allowed.
132
+ - Use the `apply_patch` tool to edit files (NEVER try `applypatch` or `apply-patch`, only `apply_patch`): {"command":["apply_patch","*** Begin Patch\\n*** Update File: path/to/file.py\\n@@ def example():\\n- pass\\n+ return 123\\n*** End Patch"]}
133
+
134
+ If completing the user's task requires writing or modifying files, your code and final answer should follow these coding guidelines, though user instructions (i.e. AGENTS.md) may override these guidelines:
135
+
136
+ - Fix the problem at the root cause rather than applying surface-level patches, when possible.
137
+ - Avoid unneeded complexity in your solution.
138
+ - Do not attempt to fix unrelated bugs or broken tests. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)
139
+ - Update documentation as necessary.
140
+ - Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.
141
+ - Use `git log` and `git blame` to search the history of the codebase if additional context is required.
142
+ - NEVER add copyright or license headers unless specifically requested.
143
+ - Do not waste tokens by re-reading files after calling `apply_patch` on them. The tool call will fail if it didn't work. The same goes for making folders, deleting folders, etc.
144
+ - Do not `git commit` your changes or create new git branches unless explicitly requested.
145
+ - Do not add inline comments within code unless explicitly requested.
146
+ - Do not use one-letter variable names unless explicitly requested.
147
+ - NEVER output inline citations like "【F:README.md†L5-L14】" in your outputs. The CLI is not able to render these so they will just be broken in the UI. Instead, if you output valid filepaths, users will be able to click on them to open the files in their editor.
148
+
149
+ ## Sandbox and approvals
150
+
151
+ The Codex CLI harness supports several different sandboxing, and approval configurations that the user can choose from.
152
+
153
+ Filesystem sandboxing prevents you from editing files without user approval. The options are:
154
+
155
+ - **read-only**: You can only read files.
156
+ - **workspace-write**: You can read files. You can write to files in your workspace folder, but not outside it.
157
+ - **danger-full-access**: No filesystem sandboxing.
158
+
159
+ Network sandboxing prevents you from accessing network without approval. Options are
160
+
161
+ - **restricted**
162
+ - **enabled**
163
+
164
+ Approvals are your mechanism to get user consent to perform more privileged actions. Although they introduce friction to the user because your work is paused until the user responds, you should leverage them to accomplish your important work. Do not let these settings or the sandbox deter you from attempting to accomplish the user's task. Approval options are
165
+
166
+ - **untrusted**: The harness will escalate most commands for user approval, apart from a limited allowlist of safe "read" commands.
167
+ - **on-failure**: The harness will allow all commands to run in the sandbox (if enabled), and failures will be escalated to the user for approval to run again without the sandbox.
168
+ - **on-request**: Commands will be run in the sandbox by default, and you can specify in your tool call if you want to escalate a command to run without sandboxing. (Note that this mode is not always available. If it is, you'll see parameters for it in the `shell` command description.)
169
+ - **never**: This is a non-interactive mode where you may NEVER ask the user for approval to run commands. Instead, you must always persist and work around constraints to solve the task for the user. You MUST do your utmost best to finish the task and validate your work before yielding. If this mode is pared with `danger-full-access`, take advantage of it to deliver the best outcome for the user. Further, in this mode, your default testing philosophy is overridden: Even if you don't see local patterns for testing, you may add tests and scripts to validate your work. Just remove them before yielding.
170
+
171
+ When you are running with approvals `on-request`, and sandboxing enabled, here are scenarios where you'll need to request approval:
172
+
173
+ - You need to run a command that writes to a directory that requires it (e.g. running tests that write to /tmp)
174
+ - You need to run a GUI app (e.g., open/xdg-open/osascript) to open browsers or files.
175
+ - You are running sandboxed and need to run a command that requires network access (e.g. installing packages)
176
+ - If you run a command that is important to solving the user's query, but it fails because of sandboxing, rerun the command with approval.
177
+ - You are about to take a potentially destructive action such as an `rm` or `git reset` that the user did not explicitly ask for
178
+ - (For all of these, you should weigh alternative paths that do not require approval.)
179
+
180
+ Note that when sandboxing is set to read-only, you'll need to request approval for any command that isn't a read.
181
+
182
+ You will be told what filesystem sandboxing, network sandboxing, and approval mode are active in a developer or user message. If you are not told about this, assume that you are running with workspace-write, network sandboxing ON, and approval on-failure.
183
+
184
+ ## Validating your work
185
+
186
+ If the codebase has tests or the ability to build or run, consider using them to verify that your work is complete.
187
+
188
+ When testing, your philosophy should be to start as specific as possible to the code you changed so that you can catch issues efficiently, then make your way to broader tests as you build confidence. If there's no test for the code you changed, and if the adjacent patterns in the codebases show that there's a logical place for you to add a test, you may do so. However, do not add tests to codebases with no tests.
189
+
190
+ Similarly, once you're confident in correctness, you can suggest or use formatting commands to ensure that your code is well formatted. If there are issues you can iterate up to 3 times to get formatting right, but if you still can't manage it's better to save the user time and present them a correct solution where you call out the formatting in your final message. If the codebase does not have a formatter configured, do not add one.
191
+
192
+ For all of testing, running, building, and formatting, do not attempt to fix unrelated bugs. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)
193
+
194
+ Be mindful of whether to run validation commands proactively. In the absence of behavioral guidance:
195
+
196
+ - When running in non-interactive approval modes like **never** or **on-failure**, proactively run tests, lint and do whatever you need to ensure you've completed the task.
197
+ - When working in interactive approval modes like **untrusted**, or **on-request**, hold off on running tests or lint commands until the user is ready for you to finalize your output, because these commands take time to run and slow down iteration. Instead suggest what you want to do next, and let the user confirm first.
198
+ - When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of approval mode. Use your judgement to decide whether this is a test-related task.
199
+
200
+ ## Ambition vs. precision
201
+
202
+ For tasks that have no prior context (i.e. the user is starting something brand new), you should feel free to be ambitious and demonstrate creativity with your implementation.
203
+
204
+ If you're operating in an existing codebase, you should make sure you do exactly what the user asks with surgical precision. Treat the surrounding codebase with respect, and don't overstep (i.e. changing filenames or variables unnecessarily). You should balance being sufficiently ambitious and proactive when completing tasks of this nature.
205
+
206
+ You should use judicious initiative to decide on the right level of detail and complexity to deliver based on the user's needs. This means showing good judgment that you're capable of doing the right extras without gold-plating. This might be demonstrated by high-value, creative touches when scope of the task is vague; while being surgical and targeted when scope is tightly specified.
207
+
208
+ ## Sharing progress updates
209
+
210
+ For especially longer tasks that you work on (i.e. requiring many tool calls, or a plan with multiple steps), you should provide progress updates back to the user at reasonable intervals. These updates should be structured as a concise sentence or two (no more than 8-10 words long) recapping progress so far in plain language: this update demonstrates your understanding of what needs to be done, progress so far (i.e. files explores, subtasks complete), and where you're going next.
211
+
212
+ Before doing large chunks of work that may incur latency as experienced by the user (i.e. writing a new file), you should send a concise message to the user with an update indicating what you're about to do to ensure they know what you're spending time on. Don't start editing or writing large files before informing the user what you are doing and why.
213
+
214
+ The messages you send before tool calls should describe what is immediately about to be done next in very concise language. If there was previous work done, this preamble message should also include a note about the work done so far to bring the user along.
215
+
216
+ ## Presenting your work and final message
217
+
218
+ Your final message should read naturally, like an update from a concise teammate. For casual conversation, brainstorming tasks, or quick questions from the user, respond in a friendly, conversational tone. You should ask questions, suggest ideas, and adapt to the user’s style. If you've finished a large amount of work, when describing what you've done to the user, you should follow the final answer formatting guidelines to communicate substantive changes. You don't need to add structured formatting for one-word answers, greetings, or purely conversational exchanges.
219
+
220
+ You can skip heavy formatting for single, simple actions or confirmations. In these cases, respond in plain sentences with any relevant next step or quick option. Reserve multi-section structured responses for results that need grouping or explanation.
221
+
222
+ The user is working on the same computer as you, and has access to your work. As such there's no need to show the full contents of large files you have already written unless the user explicitly asks for them. Similarly, if you've created or modified files using `apply_patch`, there's no need to tell users to "save the file" or "copy the code into a file"—just reference the file path.
223
+
224
+ If there's something that you think you could help with as a logical next step, concisely ask the user if they want you to do so. Good examples of this are running tests, committing changes, or building out the next logical component. If there’s something that you couldn't do (even with approval) but that the user might want to do (such as verifying changes by running the app), include those instructions succinctly.
225
+
226
+ Brevity is very important as a default. You should be very concise (i.e. no more than 10 lines), but can relax this requirement for tasks where additional detail and comprehensiveness is important for the user's understanding.
227
+
228
+ ### Final answer structure and style guidelines
229
+
230
+ You are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.
231
+
232
+ **Section Headers**
233
+
234
+ - Use only when they improve clarity — they are not mandatory for every answer.
235
+ - Choose descriptive names that fit the content
236
+ - Keep headers short (1–3 words) and in `**Title Case**`. Always start headers with `**` and end with `**`
237
+ - Leave no blank line before the first bullet under a header.
238
+ - Section headers should only be used where they genuinely improve scanability; avoid fragmenting the answer.
239
+
240
+ **Bullets**
241
+
242
+ - Use `-` followed by a space for every bullet.
243
+ - Merge related points when possible; avoid a bullet for every trivial detail.
244
+ - Keep bullets to one line unless breaking for clarity is unavoidable.
245
+ - Group into short lists (4–6 bullets) ordered by importance.
246
+ - Use consistent keyword phrasing and formatting across sections.
247
+
248
+ **Monospace**
249
+
250
+ - Wrap all commands, file paths, env vars, and code identifiers in backticks (`` `...` ``).
251
+ - Apply to inline examples and to bullet keywords if the keyword itself is a literal file/command.
252
+ - Never mix monospace and bold markers; choose one based on whether it’s a keyword (`**`) or inline code/path (`` ` ``).
253
+
254
+ **File References**
255
+ When referencing files in your response, make sure to include the relevant start line and always follow the below rules:
256
+ * Use inline code to make file paths clickable.
257
+ * Each reference should have a stand alone path. Even if it's the same file.
258
+ * Accepted: absolute, workspace‑relative, a/ or b/ diff prefixes, or bare filename/suffix.
259
+ * Line/column (1‑based, optional): :line[:column] or #Lline[Ccolumn] (column defaults to 1).
260
+ * Do not use URIs like file://, vscode://, or https://.
261
+ * Do not provide range of lines
262
+ * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\repo\project\main.rs:12:5
263
+
264
+ **Structure**
265
+
266
+ - Place related bullets together; don’t mix unrelated concepts in the same section.
267
+ - Order sections from general → specific → supporting info.
268
+ - For subsections (e.g., “Binaries” under “Rust Workspace”), introduce with a bolded keyword bullet, then list items under it.
269
+ - Match structure to complexity:
270
+ - Multi-part or detailed results → use clear headers and grouped bullets.
271
+ - Simple results → minimal headers, possibly just a short list or paragraph.
272
+
273
+ **Tone**
274
+
275
+ - Keep the voice collaborative and natural, like a coding partner handing off work.
276
+ - Be concise and factual — no filler or conversational commentary and avoid unnecessary repetition
277
+ - Use present tense and active voice (e.g., “Runs tests” not “This will run tests”).
278
+ - Keep descriptions self-contained; don’t refer to “above” or “below”.
279
+ - Use parallel structure in lists for consistency.
280
+
281
+ **Don’t**
282
+
283
+ - Don’t use literal words “bold” or “monospace” in the content.
284
+ - Don’t nest bullets or create deep hierarchies.
285
+ - Don’t output ANSI escape codes directly — the CLI renderer applies them.
286
+ - Don’t cram unrelated keywords into a single bullet; split for clarity.
287
+ - Don’t let keyword lists run long — wrap or reformat for scanability.
288
+
289
+ Generally, ensure your final answers adapt their shape and depth to the request. For example, answers to code explanations should have a precise, structured explanation with code references that answer the question directly. For tasks with a simple implementation, lead with the outcome and supplement only with what’s needed for clarity. Larger changes can be presented as a logical walkthrough of your approach, grouping related steps, explaining rationale where it adds value, and highlighting next actions to accelerate the user. Your answers should provide the right level of detail while being easily scannable.
290
+
291
+ For casual greetings, acknowledgements, or other one-off conversational messages that are not delivering substantive information or structured results, respond naturally without section headers or bullet formatting.
292
+
293
+ # Tool Guidelines
294
+
295
+ ## Shell commands
296
+
297
+ When using the shell, you must adhere to the following guidelines:
298
+
299
+ - When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)
300
+ - Read files in chunks with a max chunk size of 250 lines. Do not use python scripts to attempt to output larger chunks of a file. Command line output will be truncated after 10 kilobytes or 256 lines of output, regardless of the command used.
301
+
302
+ ## `update_plan`
303
+
304
+ A tool named `update_plan` is available to you. You can use it to keep an up‑to‑date, step‑by‑step plan for the task.
305
+
306
+ To create a new plan, call `update_plan` with a short list of 1‑sentence steps (no more than 5-7 words each) with a `status` for each step (`pending`, `in_progress`, or `completed`).
307
+
308
+ When steps have been completed, use `update_plan` to mark each finished step as `completed` and the next step you are working on as `in_progress`. There should always be exactly one `in_progress` step until everything is done. You can mark multiple items as complete in a single `update_plan` call.
309
+
310
+ If all steps are complete, ensure you call `update_plan` to mark all steps as `completed`.
@@ -0,0 +1,131 @@
1
+ """Monkey patches for pydantic-ai.
2
+
3
+ This module contains all monkey patches needed to customize pydantic-ai behavior.
4
+ These patches MUST be applied before any other pydantic-ai imports to work correctly.
5
+
6
+ Usage:
7
+ from code_puppy.pydantic_patches import apply_all_patches
8
+ apply_all_patches()
9
+ """
10
+
11
+ import importlib.metadata
12
+
13
+
14
+ def _get_code_puppy_version() -> str:
15
+ """Get the current code-puppy version."""
16
+ try:
17
+ return importlib.metadata.version("code-puppy")
18
+ except Exception:
19
+ return "0.0.0-dev"
20
+
21
+
22
+ def patch_user_agent() -> None:
23
+ """Patch pydantic-ai's User-Agent to use Code-Puppy's version.
24
+
25
+ pydantic-ai sets its own User-Agent ('pydantic-ai/x.x.x') via a @cache-decorated
26
+ function. We replace it with a dynamic function that returns:
27
+ - 'KimiCLI/0.63' for Kimi models
28
+ - 'Code-Puppy/{version}' for all other models
29
+
30
+ This MUST be called before any pydantic-ai models are created.
31
+ """
32
+ try:
33
+ import pydantic_ai.models as pydantic_models
34
+
35
+ version = _get_code_puppy_version()
36
+
37
+ # Clear cache if already called
38
+ if hasattr(pydantic_models.get_user_agent, "cache_clear"):
39
+ pydantic_models.get_user_agent.cache_clear()
40
+
41
+ def _get_dynamic_user_agent() -> str:
42
+ """Return User-Agent based on current model selection."""
43
+ try:
44
+ from code_puppy.config import get_global_model_name
45
+
46
+ model_name = get_global_model_name()
47
+ if model_name and "kimi" in model_name.lower():
48
+ return "KimiCLI/0.63"
49
+ except Exception:
50
+ pass
51
+ return f"Code-Puppy/{version}"
52
+
53
+ pydantic_models.get_user_agent = _get_dynamic_user_agent
54
+ except Exception:
55
+ pass # Don't crash on patch failure
56
+
57
+
58
+ def patch_message_history_cleaning() -> None:
59
+ """Disable overly strict message history cleaning in pydantic-ai."""
60
+ try:
61
+ from pydantic_ai import _agent_graph
62
+
63
+ _agent_graph._clean_message_history = lambda messages: messages
64
+ except Exception:
65
+ pass
66
+
67
+
68
+ def patch_process_message_history() -> None:
69
+ """Patch _process_message_history to skip strict ModelRequest validation.
70
+
71
+ Pydantic AI added a validation that history must end with ModelRequest,
72
+ but this breaks valid conversation flows. We patch it to skip that validation.
73
+ """
74
+ try:
75
+ from pydantic_ai import _agent_graph
76
+
77
+ async def _patched_process_message_history(messages, processors, run_context):
78
+ """Patched version that doesn't enforce ModelRequest at end."""
79
+ from pydantic_ai._agent_graph import (
80
+ _HistoryProcessorAsync,
81
+ _HistoryProcessorSync,
82
+ _HistoryProcessorSyncWithCtx,
83
+ cast,
84
+ exceptions,
85
+ is_async_callable,
86
+ is_takes_ctx,
87
+ run_in_executor,
88
+ )
89
+
90
+ for processor in processors:
91
+ takes_ctx = is_takes_ctx(processor)
92
+
93
+ if is_async_callable(processor):
94
+ if takes_ctx:
95
+ messages = await processor(run_context, messages)
96
+ else:
97
+ async_processor = cast(_HistoryProcessorAsync, processor)
98
+ messages = await async_processor(messages)
99
+ else:
100
+ if takes_ctx:
101
+ sync_processor_with_ctx = cast(
102
+ _HistoryProcessorSyncWithCtx, processor
103
+ )
104
+ messages = await run_in_executor(
105
+ sync_processor_with_ctx, run_context, messages
106
+ )
107
+ else:
108
+ sync_processor = cast(_HistoryProcessorSync, processor)
109
+ messages = await run_in_executor(sync_processor, messages)
110
+
111
+ if len(messages) == 0:
112
+ raise exceptions.UserError("Processed history cannot be empty.")
113
+
114
+ # NOTE: We intentionally skip the "must end with ModelRequest" validation
115
+ # that was added in newer Pydantic AI versions.
116
+
117
+ return messages
118
+
119
+ _agent_graph._process_message_history = _patched_process_message_history
120
+ except Exception:
121
+ pass
122
+
123
+
124
+ def apply_all_patches() -> None:
125
+ """Apply all pydantic-ai monkey patches.
126
+
127
+ Call this at the very top of main.py, before any other imports.
128
+ """
129
+ patch_user_agent()
130
+ patch_message_history_cleaning()
131
+ patch_process_message_history()
@@ -54,13 +54,15 @@ class ReopenableAsyncClient:
54
54
  if self._stream_context:
55
55
  return await self._stream_context.__aexit__(exc_type, exc_val, exc_tb)
56
56
 
57
- def __init__(self, **kwargs):
57
+ def __init__(self, client_class=None, **kwargs):
58
58
  """
59
59
  Initialize the ReopenableAsyncClient.
60
60
 
61
61
  Args:
62
- **kwargs: All arguments that would be passed to httpx.AsyncClient()
62
+ client_class: Class to use for creating the internal client (defaults to httpx.AsyncClient)
63
+ **kwargs: All arguments that would be passed to the client constructor
63
64
  """
65
+ self._client_class = client_class or httpx.AsyncClient
64
66
  self._client_kwargs = kwargs.copy()
65
67
  self._client: Optional[httpx.AsyncClient] = None
66
68
  self._is_closed = True
@@ -70,7 +72,7 @@ class ReopenableAsyncClient:
70
72
  Ensure the underlying client is open and ready to use.
71
73
 
72
74
  Returns:
73
- The active httpx.AsyncClient instance
75
+ The active client instance
74
76
 
75
77
  Raises:
76
78
  RuntimeError: If client cannot be opened
@@ -80,12 +82,12 @@ class ReopenableAsyncClient:
80
82
  return self._client
81
83
 
82
84
  async def _create_client(self) -> None:
83
- """Create a new httpx.AsyncClient with the stored configuration."""
85
+ """Create a new client with the stored configuration."""
84
86
  if self._client is not None and not self._is_closed:
85
87
  # Close existing client first
86
88
  await self._client.aclose()
87
89
 
88
- self._client = httpx.AsyncClient(**self._client_kwargs)
90
+ self._client = self._client_class(**self._client_kwargs)
89
91
  self._is_closed = False
90
92
 
91
93
  async def reopen(self) -> None:
@@ -171,14 +173,12 @@ class ReopenableAsyncClient:
171
173
  """
172
174
  if self._client is None or self._is_closed:
173
175
  # Create a temporary client just for building the request
174
- temp_client = httpx.AsyncClient(**self._client_kwargs)
176
+ temp_client = self._client_class(**self._client_kwargs)
175
177
  try:
176
178
  request = temp_client.build_request(method, url, **kwargs)
177
179
  return request
178
180
  finally:
179
181
  # Clean up the temporary client synchronously if possible
180
- # Note: This might leave a connection open, but it's better than
181
- # making this method async just for building requests
182
182
  pass
183
183
  return self._client.build_request(method, url, **kwargs)
184
184
 
@@ -2,18 +2,15 @@ from contextlib import asynccontextmanager, suppress
2
2
  from dataclasses import dataclass, field
3
3
  from typing import Any, AsyncIterator, List
4
4
 
5
+ from pydantic_ai._run_context import RunContext
5
6
  from pydantic_ai.models import (
6
7
  Model,
7
8
  ModelMessage,
8
- ModelSettings,
9
9
  ModelRequestParameters,
10
10
  ModelResponse,
11
+ ModelSettings,
11
12
  StreamedResponse,
12
13
  )
13
- from pydantic_ai.models.fallback import (
14
- merge_model_settings,
15
- )
16
- from pydantic_ai.result import RunContext
17
14
 
18
15
  try:
19
16
  from opentelemetry.context import get_current_span
@@ -102,15 +99,14 @@ class RoundRobinModel(Model):
102
99
  ) -> ModelResponse:
103
100
  """Make a request using the next model in the round-robin sequence."""
104
101
  current_model = self._get_next_model()
105
- # Use the current model's settings as base, then merge with provided settings
106
- merged_settings = merge_model_settings(current_model.settings, model_settings)
107
- customized_model_request_parameters = (
108
- current_model.customize_request_parameters(model_request_parameters)
102
+ # Use prepare_request to merge settings and customize parameters
103
+ merged_settings, prepared_params = current_model.prepare_request(
104
+ model_settings, model_request_parameters
109
105
  )
110
106
 
111
107
  try:
112
108
  response = await current_model.request(
113
- messages, merged_settings, customized_model_request_parameters
109
+ messages, merged_settings, prepared_params
114
110
  )
115
111
  self._set_span_attributes(current_model)
116
112
  return response
@@ -129,14 +125,13 @@ class RoundRobinModel(Model):
129
125
  ) -> AsyncIterator[StreamedResponse]:
130
126
  """Make a streaming request using the next model in the round-robin sequence."""
131
127
  current_model = self._get_next_model()
132
- # Use the current model's settings as base, then merge with provided settings
133
- merged_settings = merge_model_settings(current_model.settings, model_settings)
134
- customized_model_request_parameters = (
135
- current_model.customize_request_parameters(model_request_parameters)
128
+ # Use prepare_request to merge settings and customize parameters
129
+ merged_settings, prepared_params = current_model.prepare_request(
130
+ model_settings, model_request_parameters
136
131
  )
137
132
 
138
133
  async with current_model.request_stream(
139
- messages, merged_settings, customized_model_request_parameters, run_context
134
+ messages, merged_settings, prepared_params, run_context
140
135
  ) as response:
141
136
  self._set_span_attributes(current_model)
142
137
  yield response