MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _run_module_agent_sync

Method _run_module_agent_sync

codewiki/src/be/caw_backend.py:206–324  ·  view source on GitHub ↗
(
        self,
        module_name: str,
        components: Dict[str, Node],
        core_component_ids: List[str],
        module_path: List[str],
        working_dir: str,
        start_depth: int = 1,
        module_tree: Dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

204
205_patch_claude_allowed_tools()
206# --- end stopgap --------------------------------------------------------------
207
208
209class CawBackend(LLMBackend):
210 """Routes LLM operations through the claude / codex CLI subscription."""
211
212 def __init__(self, config: Config) -> None:
213 self._config = config
214 self._caw_provider = _resolve_caw_provider(config.provider)
215 # main_model is passed straight through; empty string → caw default.
216 self._model: str | None = config.main_model or None
217 # Resolve once, before any agent-run chdir can move the cwd —
218 # os.path.abspath is cwd-relative and _run_module_agent_sync recurses
219 # (via generate_sub_module_documentation) while the cwd is pinned.
220 self._repo_root = str(os.path.abspath(config.repo_path))
221
222 # Fail loudly here rather than producing a confusing caw error mid-run.
223 cli = _CLI_BINARY[config.provider]
224 if shutil.which(cli) is None:
225 raise RuntimeError(
226 f"Subscription mode requires the '{cli}' CLI on PATH. "
227 f"Install it and run '{cli} login', then try again."
228 )
229
230 if self._caw_provider == "claude_code":
231 # Prevent claude-code CLI from cancelling long sub-module recursion;
232 # setdefault preserves a user-supplied value (e.g. shell override).
233 os.environ.setdefault("MCP_TOOL_TIMEOUT", "86400000")
234 os.environ.setdefault("MCP_TIMEOUT", "60000")
235 logger.info(
236 "claude-code MCP timeouts: MCP_TOOL_TIMEOUT=%s MCP_TIMEOUT=%s",
237 os.environ["MCP_TOOL_TIMEOUT"],
238 os.environ["MCP_TIMEOUT"],
239 )
240
241 # ------------------------------------------------------------------
242 # Single-shot completion (clustering, parent / repo overviews)
243 # ------------------------------------------------------------------
244
245 def complete(
246 self,
247 prompt: str,
248 *,
249 model: str | None = None,
250 system_prompt: str | None = None,
251 ) -> str:
252 # Blocks the calling thread for the lifetime of the claude/codex
253 # subprocess. Callers running this from an async context (e.g. the
254 # documentation_generator) accept this — there is no concurrent work
255 # to do while clustering is in flight anyway.
256 effective_model = model or self._model
257 agent = CawAgent(
258 provider=self._caw_provider,
259 model=effective_model,
260 tools=ToolGroup.READER,
261 system_prompt=system_prompt,
262 )
263 traj = agent.completion(prompt)

Callers 1

_run_sub_modulesMethod · 0.80

Calls 14

count_tokensFunction · 0.90
is_complex_moduleFunction · 0.90
format_system_promptFunction · 0.90
CodeWikiDepsClass · 0.90
CawToolKitClass · 0.90
format_user_promptFunction · 0.90
load_jsonMethod · 0.80
infoMethod · 0.80
save_jsonMethod · 0.80

Tested by

no test coverage detected