Skip to content

Commit c551dfc

Browse files
Fook MeFook Me
authored andcommitted
Discover newly installed Codex without requiring a desktop relogin
1 parent 9e69d7b commit c551dfc

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎packages/shadowfetch-missions/data/usr/lib/shadowfetch/missions/sf_mission_account.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class AccountError(RuntimeError):
1313
pass
1414

1515

16+
def codex_executable():
17+
"""Find a first-run install before the desktop has refreshed its PATH."""
18+
return shutil.which('codex') or shutil.which('codex', path=str(Path.home() / '.local/bin'))
19+
20+
1621
def account_home(*, create=False):
1722
home = Path.home()
1823
parent = home
@@ -65,7 +70,7 @@ def main(argv=None):
6570
try:
6671
if os.getuid() == 0:
6772
raise AccountError('Run this as your desktop user, not root')
68-
codex = shutil.which('codex')
73+
codex = codex_executable()
6974
if not codex:
7075
raise AccountError('Install Codex from the agent setup first')
7176
home = account_home(create=args.action == 'login')

‎packages/shadowfetch-missions/data/usr/lib/shadowfetch/missions/sf_missions.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ def checkpoint_call(name, ws, **kwargs):
361361
raise MissionError(f"Workspace {name} failed: {clean(exc)}")
362362

363363
def executable(name):
364-
found = shutil.which(name)
364+
sys.path.insert(0, str(Path(__file__).resolve().parent))
365+
from sf_mission_account import codex_executable
366+
found = codex_executable() if name == "codex" else shutil.which(name)
365367
if found:
366368
return found
367369
for parent in Path(__file__).resolve().parents:
@@ -786,14 +788,14 @@ def review(store, mid, decision):
786788

787789
def capabilities():
788790
sys.path.insert(0, str(Path(__file__).resolve().parent))
789-
from sf_mission_account import account_home, AccountError
791+
from sf_mission_account import account_home, AccountError, codex_executable
790792
try:
791793
dedicated_account_present = (account_home() / "auth.json").is_file()
792794
except (AccountError, OSError):
793795
dedicated_account_present = False
794796
credential_file = Path.home() / ".config/shadowfetch/missions/codex.env"
795797
credential_file_present = credential_file.is_file() and not credential_file.is_symlink() and credential_file.stat().st_uid == os.getuid() and not stat.S_IMODE(credential_file.stat().st_mode) & 0o077
796-
return {"version": VERSION, "workspace_root": str(workspace_root()), "runtimes": {"offline": {"kinds": ["media"], "requires_network_approval": False}, "codex": {"kinds": ["code", "report"], "installed": bool(shutil.which("codex")), "api_key_configured": bool(os.environ.get("CODEX_API_KEY") or os.environ.get("OPENAI_API_KEY")), "dedicated_account_present": dedicated_account_present, "worker_environment_file": str(credential_file), "worker_environment_file_present": credential_file_present, "configuration": "Run shadowfetch-mission-account login for a dedicated account, or save a user-owned0600 CODEX_API_KEY environment file and restart the idle worker. Credential presence does not verify authentication.", "requires_network_approval": True, "authentication": "Dedicated Codex account or worker API key; stored credentials are not a verified login"}}, "tools": {name: bool(shutil.which(name)) for name in ("bwrap", "ffmpeg", "ffprobe", "shadowfetch-firebreak")}, "kinds": ["code", "report", "media"], "states": ["queued", "running", "waiting-review", "completed", "failed", "cancelled", "undone"], "max_attempts": 3, "max_parallel": 1, "local_ai": "deferred", "grok_bot": "Launch the official desktop cloud teammate separately; it has no supported mission CLI adapter"}
798+
return {"version": VERSION, "workspace_root": str(workspace_root()), "runtimes": {"offline": {"kinds": ["media"], "requires_network_approval": False}, "codex": {"kinds": ["code", "report"], "installed": bool(codex_executable()), "api_key_configured": bool(os.environ.get("CODEX_API_KEY") or os.environ.get("OPENAI_API_KEY")), "dedicated_account_present": dedicated_account_present, "worker_environment_file": str(credential_file), "worker_environment_file_present": credential_file_present, "configuration": "Run shadowfetch-mission-account login for a dedicated account, or save a user-owned0600 CODEX_API_KEY environment file and restart the idle worker. Credential presence does not verify authentication.", "requires_network_approval": True, "authentication": "Dedicated Codex account or worker API key; stored credentials are not a verified login"}}, "tools": {name: bool(shutil.which(name)) for name in ("bwrap", "ffmpeg", "ffprobe", "shadowfetch-firebreak")}, "kinds": ["code", "report", "media"], "states": ["queued", "running", "waiting-review", "completed", "failed", "cancelled", "undone"], "max_attempts": 3, "max_parallel": 1, "local_ai": "deferred", "grok_bot": "Launch the official desktop cloud teammate separately; it has no supported mission CLI adapter"}
797799

798800

799801
def worker(store, once=False):

‎packages/shadowfetch-missions/tests/test_mission_account.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ def setUp(self):
2121
self.patch.start()
2222
self.addCleanup(self.patch.stop)
2323

24+
def test_fresh_install_without_desktop_path_refresh(self):
25+
binary = self.home / '.local/bin/codex'
26+
binary.parent.mkdir(parents=True)
27+
binary.write_text('#!/bin/sh\nexit 0\n')
28+
with patch.dict(os.environ, {'PATH': '/nonexistent'}):
29+
self.assertIsNone(account.codex_executable())
30+
binary.chmod(0o755)
31+
self.assertEqual(account.codex_executable(), str(binary))
32+
2433
def test_missing_login_does_not_create_storage(self):
2534
with self.assertRaises(account.AccountError):
2635
account.account_home()

‎tools/qa_4_0_0/native_mission_acceptance.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def cli(*values):
4444

4545
try:
4646
capabilities = cli('capabilities')
47-
check('Codex CLI installed and API key configured for this QA process', capabilities['runtimes']['codex']['installed'] and capabilities['runtimes']['codex']['api_key_configured'])
47+
check('Codex CLI installed and credentials available; real inference verified below', capabilities['runtimes']['codex']['installed'] and (capabilities['runtimes']['codex']['api_key_configured'] or capabilities['runtimes']['codex'].get('dedicated_account_present', False)))
4848
if args.kind == 'code':
4949
(scope / 'title.py').write_text('def normalize_title(title):\n return title\n')
5050
tests = "from title import normalize_title\nassert normalize_title(' Shadowfetch \\n Linux ') == 'Shadowfetch Linux'\nassert normalize_title('Ice\\tEdition') == 'Ice Edition'\nassert normalize_title(' café 日本語 ') == 'café 日本語'\nassert normalize_title(' ') == ''\nprint('4 independent normalization checks passed')\n"

0 commit comments

Comments
 (0)