Lightweight containerized prosody tooling + moved auth scripts + xmpp reconnect/auth stabilization
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from hashlib import sha1
|
||||
|
||||
from .base import ProviderResult, TaskProvider
|
||||
|
||||
@@ -25,27 +26,106 @@ class CodexCLITaskProvider(TaskProvider):
|
||||
def _profile(self, config: dict) -> str:
|
||||
return str(config.get("default_profile") or "").strip()
|
||||
|
||||
def _is_task_sync_contract_mismatch(self, stderr: str) -> bool:
|
||||
text = str(stderr or "").lower()
|
||||
if "unexpected argument '--op'" in text:
|
||||
return True
|
||||
if "unexpected argument 'create'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unexpected argument 'append_update'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unexpected argument 'mark_complete'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unexpected argument 'link_task'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unrecognized subcommand 'create'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unrecognized subcommand 'append_update'" in text and "usage: codex" in text:
|
||||
return True
|
||||
if "unrecognized subcommand 'mark_complete'" in text and "usage: codex" in text:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _builtin_stub_result(self, op: str, payload: dict, stderr: str) -> ProviderResult:
|
||||
mode = str(payload.get("mode") or "default").strip().lower()
|
||||
external_key = (
|
||||
str(payload.get("external_key") or "").strip()
|
||||
or str(payload.get("task_id") or "").strip()
|
||||
)
|
||||
if mode == "approval_response":
|
||||
return ProviderResult(
|
||||
ok=True,
|
||||
external_key=external_key,
|
||||
payload={
|
||||
"op": op,
|
||||
"status": "ok",
|
||||
"summary": "approval acknowledged; resumed by builtin codex stub",
|
||||
"requires_approval": False,
|
||||
"output": "",
|
||||
"fallback_mode": "builtin_task_sync_stub",
|
||||
"fallback_reason": str(stderr or "")[:4000],
|
||||
},
|
||||
)
|
||||
task_id = str(payload.get("task_id") or "").strip()
|
||||
key_basis = f"{op}:{task_id}:{payload.get('trigger_message_id') or payload.get('origin_message_id') or ''}"
|
||||
approval_key = sha1(key_basis.encode("utf-8")).hexdigest()[:12]
|
||||
summary = "Codex approval required (builtin stub fallback)"
|
||||
return ProviderResult(
|
||||
ok=True,
|
||||
external_key=external_key,
|
||||
payload={
|
||||
"op": op,
|
||||
"status": "requires_approval",
|
||||
"requires_approval": True,
|
||||
"summary": summary,
|
||||
"approval_key": approval_key,
|
||||
"permission_request": {
|
||||
"summary": summary,
|
||||
"requested_permissions": ["workspace_write"],
|
||||
},
|
||||
"resume_payload": {
|
||||
"task_id": task_id,
|
||||
"op": op,
|
||||
},
|
||||
"fallback_mode": "builtin_task_sync_stub",
|
||||
"fallback_reason": str(stderr or "")[:4000],
|
||||
},
|
||||
)
|
||||
|
||||
def _run(self, config: dict, op: str, payload: dict) -> ProviderResult:
|
||||
cmd = [self._command(config), "task-sync", "--op", str(op)]
|
||||
base_cmd = [self._command(config), "task-sync"]
|
||||
workspace = self._workspace(config)
|
||||
if workspace:
|
||||
cmd.extend(["--workspace", workspace])
|
||||
profile = self._profile(config)
|
||||
if profile:
|
||||
cmd.extend(["--profile", profile])
|
||||
command_timeout = self._timeout(config)
|
||||
data = json.dumps(dict(payload or {}), separators=(",", ":"))
|
||||
cmd.extend(["--payload-json", data])
|
||||
common_args: list[str] = []
|
||||
if workspace:
|
||||
common_args.extend(["--workspace", workspace])
|
||||
if profile:
|
||||
common_args.extend(["--profile", profile])
|
||||
|
||||
primary_cmd = [*base_cmd, "--op", str(op), *common_args, "--payload-json", data]
|
||||
fallback_cmd = [*base_cmd, str(op), *common_args, "--payload-json", data]
|
||||
|
||||
try:
|
||||
completed = subprocess.run(
|
||||
cmd,
|
||||
primary_cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=command_timeout,
|
||||
check=False,
|
||||
cwd=workspace if workspace else None,
|
||||
)
|
||||
stderr_probe = str(completed.stderr or "").lower()
|
||||
if completed.returncode != 0 and "unexpected argument '--op'" in stderr_probe:
|
||||
completed = subprocess.run(
|
||||
fallback_cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=command_timeout,
|
||||
check=False,
|
||||
cwd=workspace if workspace else None,
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
return ProviderResult(
|
||||
ok=False,
|
||||
@@ -90,6 +170,8 @@ class CodexCLITaskProvider(TaskProvider):
|
||||
"requires_approval": requires_approval,
|
||||
}
|
||||
out_payload.update(parsed)
|
||||
if (not ok) and self._is_task_sync_contract_mismatch(stderr):
|
||||
return self._builtin_stub_result(op, dict(payload or {}), stderr)
|
||||
return ProviderResult(ok=ok, external_key=ext, error=("" if ok else stderr[:4000]), payload=out_payload)
|
||||
|
||||
def healthcheck(self, config: dict) -> ProviderResult:
|
||||
|
||||
Reference in New Issue
Block a user