Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `dyro dispatch backends` 在 Grok CLI 只配置了 API key、`grok models` 未打印会话登录句时,也会识别为已认证;CLI 明确表示未登录时仍视为未认证。

## 0.7.17 - 2026-11-14

对使用者的影响:开发线可以退役、可以在兄弟线之间合并、可以合回基线,多仓操作中断后能查明每个仓的状态;`dyro next` 认得当前所在的开发线;`dyro dispatch` 失败不再显示为成功。**兼容性注意**:成功执行带 `--push` 的 `line merge`、`line sync` 或 `task merge` 后,目标线清单升级为 schema 4(新增 `[remote_anchors]`)。0.7.16 及更早版本无法解析 schema 4 清单;由于它会扫描全部清单,同一工作区里其他开发线的 `status`、`next`、`line merge` 等命令也会失败。访问同一工作区的所有客户端须一起升级,不承诺降级兼容。新版读取旧清单不迁移、不改文件。
Expand Down
20 changes: 17 additions & 3 deletions experiments/local_agent_dispatch/adapters/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,15 +1886,29 @@ def run(
)


def _grok_models_confirms_login(stdout: str) -> bool:
"""Accept only grok models banners captured from a logged-in CLI.

A session prints "You are logged in with". An API key with no session
prints "You are using XAI_API_KEY." A logged-out CLI still exits 0 and
prints "You are not authenticated."; that marker wins if both appear.
"""
plain = re.sub(r"\x1b\[[0-9;]*m", "", stdout)
if "You are not authenticated" in plain:
return False
return (
"You are logged in with" in plain or "You are using XAI_API_KEY" in plain
)


class GrokAdapter(SubprocessCliAdapter):
def authenticated(self) -> bool:
completed = self._probe(["grok", "models"], timeout_seconds=10.0)
if completed is None:
return False
plain = re.sub(r"\x1b\[[0-9;]*m", "", completed.stdout)
ready = "You are logged in with" in plain
ready = _grok_models_confirms_login(completed.stdout)
if not ready:
self._probe_failure_reason = "Grok models did not confirm a logged-in session"
self._probe_failure_reason = "Grok models did not confirm authentication"
return ready

def run(
Expand Down
73 changes: 55 additions & 18 deletions tests/test_adversarial_remediation_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,27 +2166,64 @@ def test_cursor_dispatch_auth_uses_cli_login_and_positive_status(self) -> None:
self.assertEqual(adapter.authenticated(), expected)
self.assertEqual(bounded.call_args.args[0], ["cursor-agent", "status"])

def test_grok_auth_rejects_unauthenticated_model_listing(self) -> None:
completed = BoundedCompletedProcess(
args=("grok",),
returncode=0,
stdout=(
"You are not authenticated.\n"
"Available models:\n * grok-4.5\n"
),
stderr="",
def test_grok_auth_matches_captured_models_banners(self) -> None:
logged_out = (
"You are not authenticated.\n\n"
"Default model: grok-4.6\n\n"
"Available models:\n"
" * grok-4.6 (default)\n"
" - grok-4.5\n"
)
with (
patch(
"experiments.local_agent_dispatch.adapters.subprocess_cli.shutil.which",
return_value="/usr/local/bin/grok",
cases = (
(
"You are logged in with a local session.\n\n"
"Default model: grok-4.7\n\n"
"Available models:\n - grok-4.7\n",
True,
),
patch(
"experiments.local_agent_dispatch.adapters.subprocess_cli.run_bounded",
return_value=completed,
("\x1b[32mYou are logged in with a local session.\x1b[0m\n", True),
(
"You are using XAI_API_KEY.\n\n"
"Default model: grok-4.6\n\n"
"Available models:\n"
" * grok-4.6 (default)\n"
" - grok-4.5\n",
True,
),
):
self.assertFalse(grok_adapter().authenticated())
(logged_out, False),
(
"You are not authenticated.\n"
"Available models:\n * grok-4.5\n",
False,
),
(logged_out + "You are using XAI_API_KEY.\n", False),
("Available models:\n * grok-4.5\n", False),
)
for stdout, expected in cases:
completed = BoundedCompletedProcess(
args=("grok",),
returncode=0,
stdout=stdout,
stderr="",
)
adapter = grok_adapter()
with (
patch(
"experiments.local_agent_dispatch.adapters.subprocess_cli.shutil.which",
return_value="/usr/local/bin/grok",
),
patch(
"experiments.local_agent_dispatch.adapters.subprocess_cli.run_bounded",
return_value=completed,
) as bounded,
):
self.assertEqual(adapter.authenticated(), expected)
self.assertEqual(bounded.call_args.args[0], ["grok", "models"])
if not expected:
self.assertEqual(
adapter.readiness_reason(),
"Grok models did not confirm authentication",
)

def test_hermes_auth_is_bound_to_selected_provider(self) -> None:
completed = BoundedCompletedProcess(
Expand Down
Loading