Skip to content

Commit c67a942

Browse files
authored
Merge pull request #18 from semantic-developer/feature/sd-20
fix update for new api key args in codex cli
2 parents 7bacd39 + 8fa193a commit c67a942

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ A cross‑platform desktop UI (Avalonia/.NET 8) for driving the Codex CLI app se
4040
- Verbose logging (show suppressed output)
4141
- Enable MCP support (loads MCP servers from your JSON config and passes them directly to Codex)
4242
- Config path: `~/.config/SemanticDeveloper/mcp_servers.json` (Linux/macOS) or `%AppData%/SemanticDeveloper/mcp_servers.json` (Windows)
43-
- Use API Key for Codex CLI (runs `codex login --api-key <key>` before sessions; does not rely on existing CLI auth)
43+
- Use API Key for Codex CLI (pipes the key to `codex login --with-api-key` before sessions; does not rely on existing CLI auth)
4444
- Allow network access for tools (sets sandbox_policy.network_access=true on turns so MCP tools can reach the network)
4545
- Without API key enabled, the app proactively authenticates with `codex auth login` (falling back to `codex login`) before sessions so your chat/GPT token is used.
4646

@@ -213,7 +213,7 @@ Selection behavior:
213213
- Authentication:
214214
- If you are not using an API key and the Codex CLI is not logged in (no `~/.codex/auth.json`), the app-server stream returns 401. The app detects this and prompts to run `codex auth login` for you. Follow the browser flow; on success the app restarts the session automatically.
215215
- If your CLI version doesn’t support `auth login`, the app falls back to `codex login`.
216-
- When “Use API Key” is enabled in CLI Settings, the app attempts a non‑interactive `codex login --api-key <key>` before sessions and on 401. If login succeeds, it restarts the session automatically.
216+
- When “Use API Key” is enabled in CLI Settings, the app pipes your key into `codex login --with-api-key` before sessions and on 401. If login succeeds, it restarts the session automatically.
217217

218218
## Run App
219219

SemanticDeveloper/SemanticDeveloper/MainWindow.axaml.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,7 @@ private async Task<int> RunCodexLoginWithApiKeyAsync(string apiKey)
33703370
: Directory.GetCurrentDirectory();
33713371
try
33723372
{
3373-
var psi = await _cli.BuildProcessStartInfoAsync(cwd, new[] { "login", "--api-key", apiKey }, redirectStdIn: false);
3373+
var psi = await _cli.BuildProcessStartInfoAsync(cwd, new[] { "login", "--with-api-key" }, redirectStdIn: true);
33743374

33753375
using (var p = new Process { StartInfo = psi, EnableRaisingEvents = true })
33763376
{
@@ -3379,19 +3379,35 @@ private async Task<int> RunCodexLoginWithApiKeyAsync(string apiKey)
33793379
if (!p.Start()) return -1;
33803380
p.BeginOutputReadLine();
33813381
p.BeginErrorReadLine();
3382+
try
3383+
{
3384+
p.StandardInput.NewLine = "\n";
3385+
await p.StandardInput.WriteLineAsync(apiKey);
3386+
await p.StandardInput.FlushAsync();
3387+
p.StandardInput.Close();
3388+
}
3389+
catch { }
33823390
await p.WaitForExitAsync();
33833391
if (p.ExitCode == 0) return 0;
33843392
}
33853393

3386-
// Fallback: codex auth login --api-key <key>
3387-
var psi2 = await _cli.BuildProcessStartInfoAsync(cwd, new[] { "auth", "login", "--api-key", apiKey }, redirectStdIn: false);
3394+
// Fallback: codex auth login --with-api-key
3395+
var psi2 = await _cli.BuildProcessStartInfoAsync(cwd, new[] { "auth", "login", "--with-api-key" }, redirectStdIn: true);
33883396

33893397
using var p2 = new Process { StartInfo = psi2, EnableRaisingEvents = true };
33903398
p2.OutputDataReceived += (_, ev) => { if (!string.IsNullOrWhiteSpace(ev.Data)) AppendCliLog(ev.Data!); };
33913399
p2.ErrorDataReceived += (_, ev) => { if (!string.IsNullOrWhiteSpace(ev.Data)) AppendCliLog(ev.Data!); };
33923400
if (!p2.Start()) return -1;
33933401
p2.BeginOutputReadLine();
33943402
p2.BeginErrorReadLine();
3403+
try
3404+
{
3405+
p2.StandardInput.NewLine = "\n";
3406+
await p2.StandardInput.WriteLineAsync(apiKey);
3407+
await p2.StandardInput.FlushAsync();
3408+
p2.StandardInput.Close();
3409+
}
3410+
catch { }
33953411
await p2.WaitForExitAsync();
33963412
return p2.ExitCode;
33973413
}

SemanticDeveloper/SemanticDeveloper/Services/CodexCliService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public async Task StartAsync(string workspacePath, CancellationToken cancellatio
2727
if (IsRunning)
2828
throw new InvalidOperationException("CLI already running.");
2929

30-
// Force proto subcommand per environment ("codex proto")
30+
// Force app-server subcommand per environment ("codex app-server")
3131
var tokens = BuildArgumentTokens(AdditionalArgs);
3232
var effectiveWorkspace = string.IsNullOrWhiteSpace(workspacePath) ? Directory.GetCurrentDirectory() : workspacePath;
3333
var psi = await BuildProcessStartInfoAsync(effectiveWorkspace, tokens, redirectStdIn: true);
3434

35-
// Do not inject API key via environment. Authentication is handled via an explicit
36-
// 'codex login --api-key' flow before starting the proto session.
35+
// Do not inject API key via environment. Authentication is handled via the explicit
36+
// 'codex login --with-api-key' flow before starting the app-server session.
3737

3838
// Emit the exact command being launched to the debug console (not UI)
3939
try

SemanticDeveloper/SemanticDeveloper/Views/CliSettingsDialog.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<TextBox Text="{Binding ApiKey, Mode=TwoWay}"
3131
PasswordChar=""
3232
Watermark="Enter API key"
33-
ToolTip.Tip="When enabled, the app runs 'codex login --api-key &lt;key&gt;' before sessions"
33+
ToolTip.Tip="When enabled, the app pipes your key to 'codex login --with-api-key' before sessions"
3434
MaxWidth="550"/>
3535
<TextBlock Margin="0,6,0,0" Foreground="#888" FontSize="12" Text="Stored in settings.json. When enabled, the app authenticates with your key and does not rely on existing CLI login." MaxWidth="550" TextWrapping="Wrap"/>
3636
</StackPanel>

0 commit comments

Comments
 (0)