feat: add user-assisted xdfx skill flow
This commit is contained in:
1 parent
f5efe9b041
commit
2215ec3c49
20 files changed
+4314
-761
No files matched your search
@@ -15,6 +15,10 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
if hasattr(sys.stderr, "reconfigure"):
|
||||
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
STEPS = ("step1", "step2", "step3", "step4", "step5", "step6")
|
||||
|
||||
@@ -53,7 +57,7 @@ def selected_steps(first: str, last: str) -> list[str]:
|
||||
return list(STEPS[start : end + 1])
|
||||
|
||||
|
||||
def stream_command(step: str, cmd: list[str]) -> int:
|
||||
def stream_command(step: str, cmd: list[str]) -> tuple[int, bool]:
|
||||
"""Run one step and forward stdout/stderr lines as they are produced."""
|
||||
print(f"运行步骤:{STEP_LABELS.get(step, step)};执行命令:" + " ".join(cmd), flush=True)
|
||||
env = os.environ.copy()
|
||||
@@ -68,10 +72,13 @@ def stream_command(step: str, cmd: list[str]) -> int:
|
||||
env=env,
|
||||
)
|
||||
assert process.stdout is not None
|
||||
waiting_user = False
|
||||
for line in process.stdout:
|
||||
if line.startswith("用户协助 "):
|
||||
waiting_user = True
|
||||
sys.stdout.buffer.write(line.encode("utf-8", errors="replace"))
|
||||
sys.stdout.buffer.flush()
|
||||
return process.wait()
|
||||
return process.wait(), waiting_user
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
@@ -83,7 +90,10 @@ def main(argv: list[str] | None = None) -> int:
|
||||
# Keep all business flags unchanged so the wrapper behaves like a thin
|
||||
# streaming version of repeated xdfx_flow.py --mode stepN calls.
|
||||
cmd = [sys.executable, str(flow_script), "--mode", step, *passthrough]
|
||||
code = stream_command(step, cmd)
|
||||
code, waiting_user = stream_command(step, cmd)
|
||||
if waiting_user:
|
||||
print("已发起用户协助,暂停后续步骤;请根据用户选择重跑当前步骤。", flush=True)
|
||||
return code
|
||||
if code:
|
||||
exit_code = code
|
||||
if not args.continue_on_error:
|
||||
|
||||
Reference in new issue
Block a user