feat(ack): add grok workers and allow --always-approve
Grok is a first-class worker CLI. Launcher argv includes --always-approve so unattended tool calls are not blocked; sandbox stays required.
This commit is contained in:
@@ -39,8 +39,10 @@ if str(SCRIPT_DIR) not in sys.path:
|
||||
|
||||
from validate_tasks import load_document, validate_builtin # noqa: E402
|
||||
from worker_profiles import ( # noqa: E402
|
||||
GROK_EXECUTABLE_NAME_RE,
|
||||
LAUNCH_PROTOCOL_VERSION,
|
||||
canonical_sha256,
|
||||
executable_basename_matches_cli,
|
||||
profile_hash,
|
||||
render_worker_argv,
|
||||
validate_routing_document,
|
||||
@@ -81,6 +83,12 @@ WORKER_ENVIRONMENT_NAMES = CONTROL_ENVIRONMENT_NAMES | {
|
||||
WORKER_CREDENTIAL_NAMES = {
|
||||
"codex": frozenset({"AZURE_OPENAI_API_KEY", "OPENAI_API_KEY"}),
|
||||
"cursor-agent": frozenset({"CURSOR_API_KEY"}),
|
||||
"grok": frozenset({"XAI_API_KEY"}),
|
||||
}
|
||||
CLI_TITLE_LABELS = {
|
||||
"codex": "CODEX",
|
||||
"cursor-agent": "CURSOR",
|
||||
"grok": "GROK",
|
||||
}
|
||||
INHERITED_ENVIRONMENT_PREFIXES = (
|
||||
"LC_",
|
||||
@@ -263,8 +271,41 @@ def load_authoritative_board(project_root_value: str) -> tuple[Path, dict]:
|
||||
return project_root, board
|
||||
|
||||
|
||||
def _is_under_real_grok_home(resolved: Path) -> bool:
|
||||
"""Return True when ``resolved`` is under a non-symlink ``$HOME/.grok``."""
|
||||
|
||||
home, _ = account_identity()
|
||||
grok_root = home / ".grok"
|
||||
try:
|
||||
root_metadata = os.lstat(grok_root)
|
||||
if stat.S_ISLNK(root_metadata.st_mode) or not stat.S_ISDIR(root_metadata.st_mode):
|
||||
return False
|
||||
grok_root.resolve(strict=True)
|
||||
resolved.relative_to(grok_root.resolve(strict=True))
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _is_trusted_grok_executable(resolved: Path, metadata: os.stat_result) -> bool:
|
||||
"""Accept Grok's vendor artifact names under ``~/.grok``, or a 0755 ``grok``."""
|
||||
|
||||
if GROK_EXECUTABLE_NAME_RE.fullmatch(resolved.name) is None:
|
||||
return False
|
||||
if not executable_basename_matches_cli(str(resolved), "grok"):
|
||||
return False
|
||||
mode = stat.S_IMODE(metadata.st_mode)
|
||||
if mode & 0o002:
|
||||
return False
|
||||
if resolved.name == "grok" and not (mode & 0o020):
|
||||
return True
|
||||
if not _is_under_real_grok_home(resolved):
|
||||
return False
|
||||
return metadata.st_uid == os.getuid() and metadata.st_gid == os.getgid()
|
||||
|
||||
|
||||
def resolve_executable(name: str) -> Path:
|
||||
supported = {"codex", "cursor-agent", "git", "orca"}
|
||||
supported = {"codex", "cursor-agent", "grok", "git", "orca"}
|
||||
if name not in supported:
|
||||
raise LaunchError(f"不支持的可执行文件: {name}")
|
||||
search_paths = trusted_path_entries()
|
||||
@@ -289,6 +330,10 @@ def resolve_executable(name: str) -> Path:
|
||||
continue
|
||||
if metadata.st_uid not in {0, os.getuid()}:
|
||||
continue
|
||||
if name == "grok":
|
||||
if _is_trusted_grok_executable(resolved, metadata):
|
||||
return resolved
|
||||
continue
|
||||
if stat.S_IMODE(metadata.st_mode) & 0o022:
|
||||
continue
|
||||
if resolved.name != name:
|
||||
@@ -697,7 +742,10 @@ def build_plan(
|
||||
"slot": slot,
|
||||
}
|
||||
)
|
||||
cli_label = "CODEX" if profile["cli"] == "codex" else "CURSOR"
|
||||
try:
|
||||
cli_label = CLI_TITLE_LABELS[str(profile["cli"])]
|
||||
except KeyError as exc:
|
||||
raise LaunchError(f"不支持的 worker CLI: {profile['cli']}") from exc
|
||||
role_label = "DEV" if role == "developer" else "TEST"
|
||||
digest_short = launch_fingerprint.split(":", 1)[-1][:10]
|
||||
title = (
|
||||
|
||||
Reference in New Issue
Block a user