@hunyed15/codecgc 0.1.5 → 0.1.7

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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import asyncio
6
+ import functools
5
7
  import json
6
8
  import os
7
9
  import queue
@@ -134,12 +136,11 @@ def _validate_backend_target_paths(target_paths: List[Path]) -> tuple[bool, List
134
136
  return True, policy_checks, ""
135
137
 
136
138
 
137
- def run_shell_command(cmd: list[str], cwd: Optional[Path] = None) -> Generator[str, None, None]:
139
+ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]:
138
140
  """Execute a command and stream its output line-by-line.
139
141
 
140
142
  Args:
141
143
  cmd: Command and arguments as a list (e.g., ["codex", "exec", "prompt"])
142
- cwd: Optional working directory for the command
143
144
 
144
145
  Yields:
145
146
  Output lines from the command
@@ -158,7 +159,6 @@ def run_shell_command(cmd: list[str], cwd: Optional[Path] = None) -> Generator[s
158
159
  stderr=subprocess.STDOUT,
159
160
  universal_newlines=True,
160
161
  encoding='utf-8',
161
- cwd=str(cwd) if cwd else None, # 添加 cwd 参数,确保在正确的工作目录中运行
162
162
  )
163
163
 
164
164
  output_queue: queue.Queue[str | None] = queue.Queue()
@@ -265,7 +265,7 @@ def _execute_codex_session(
265
265
  err_message = ""
266
266
  thread_id: Optional[str] = None
267
267
 
268
- for line in run_shell_command(cmd, cwd=cd):
268
+ for line in run_shell_command(cmd):
269
269
  try:
270
270
  line_dict = json.loads(line.strip())
271
271
  all_messages.append(line_dict)
@@ -409,17 +409,20 @@ async def codex(
409
409
  ] = "",
410
410
  ) -> Dict[str, Any]:
411
411
  """Execute a Codex CLI session and return the results."""
412
- return _execute_codex_session(
413
- prompt=PROMPT,
414
- cd=cd,
415
- sandbox=sandbox,
416
- session_id=SESSION_ID,
417
- skip_git_repo_check=skip_git_repo_check,
418
- return_all_messages=return_all_messages,
419
- image=image,
420
- model=model,
421
- yolo=yolo,
422
- profile=profile,
412
+ return await asyncio.to_thread(
413
+ functools.partial(
414
+ _execute_codex_session,
415
+ prompt=PROMPT,
416
+ cd=cd,
417
+ sandbox=sandbox,
418
+ session_id=SESSION_ID,
419
+ skip_git_repo_check=skip_git_repo_check,
420
+ return_all_messages=return_all_messages,
421
+ image=image,
422
+ model=model,
423
+ yolo=yolo,
424
+ profile=profile,
425
+ )
423
426
  )
424
427
 
425
428
 
@@ -495,17 +498,20 @@ async def implement_backend_task(
495
498
  constraints=constraints,
496
499
  acceptance_criteria=acceptance_criteria,
497
500
  )
498
- result = _execute_codex_session(
499
- prompt=prompt,
500
- cd=cd,
501
- sandbox=sandbox,
502
- session_id=SESSION_ID,
503
- skip_git_repo_check=True,
504
- return_all_messages=return_all_messages,
505
- image=[],
506
- model=model,
507
- yolo=False,
508
- profile=profile,
501
+ result = await asyncio.to_thread(
502
+ functools.partial(
503
+ _execute_codex_session,
504
+ prompt=prompt,
505
+ cd=cd,
506
+ sandbox=sandbox,
507
+ session_id=SESSION_ID,
508
+ skip_git_repo_check=True,
509
+ return_all_messages=return_all_messages,
510
+ image=[],
511
+ model=model,
512
+ yolo=False,
513
+ profile=profile,
514
+ )
509
515
  )
510
516
 
511
517
  if not result.get("success"):
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import asyncio
6
+ import functools
5
7
  import json
6
8
  import os
7
9
  import queue
@@ -359,13 +361,16 @@ async def gemini(
359
361
  ] = "",
360
362
  ) -> Dict[str, Any]:
361
363
  """Execute a gemini CLI session and return the results."""
362
- return _execute_gemini_session(
363
- prompt=PROMPT,
364
- cd=cd,
365
- sandbox=sandbox,
366
- session_id=SESSION_ID,
367
- return_all_messages=return_all_messages,
368
- model=model,
364
+ return await asyncio.to_thread(
365
+ functools.partial(
366
+ _execute_gemini_session,
367
+ prompt=PROMPT,
368
+ cd=cd,
369
+ sandbox=sandbox,
370
+ session_id=SESSION_ID,
371
+ return_all_messages=return_all_messages,
372
+ model=model,
373
+ )
369
374
  )
370
375
 
371
376
 
@@ -433,13 +438,16 @@ async def implement_frontend_task(
433
438
  constraints=constraints,
434
439
  acceptance_criteria=acceptance_criteria,
435
440
  )
436
- result = _execute_gemini_session(
437
- prompt=prompt,
438
- cd=cd,
439
- sandbox=sandbox,
440
- session_id=SESSION_ID,
441
- return_all_messages=return_all_messages,
442
- model=model,
441
+ result = await asyncio.to_thread(
442
+ functools.partial(
443
+ _execute_gemini_session,
444
+ prompt=prompt,
445
+ cd=cd,
446
+ sandbox=sandbox,
447
+ session_id=SESSION_ID,
448
+ return_all_messages=return_all_messages,
449
+ model=model,
450
+ )
443
451
  )
444
452
 
445
453
  if not result.get("success"):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hunyed15/codecgc",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Claude-hosted multi-model workflow product shell for CodeCGC.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import os
2
3
  import subprocess
3
4
  import sys
4
5
  from pathlib import Path
@@ -25,6 +26,11 @@ def parse_json_text(text: str) -> dict[str, Any]:
25
26
 
26
27
  def run_json_script(script_name: str, *args: str) -> dict[str, Any]:
27
28
  command = build_script_command(script_name, *args)
29
+
30
+ # 设置环境变量,确保子进程使用正确的工作目录
31
+ env = os.environ.copy()
32
+ env["CODECGC_WORKSPACE_ROOT"] = str(PROJECT_WORKSPACE)
33
+
28
34
  completed = subprocess.run(
29
35
  command,
30
36
  cwd=PROJECT_WORKSPACE,
@@ -33,6 +39,7 @@ def run_json_script(script_name: str, *args: str) -> dict[str, Any]:
33
39
  text=True,
34
40
  encoding="utf-8",
35
41
  errors="replace",
42
+ env=env, # 传递环境变量
36
43
  )
37
44
 
38
45
  stdout = completed.stdout.strip()