Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

LLM-1521: reattach stdin to /dev/tty when piped#50

Merged
castabar merged 2 commits into
mainfrom
fix/install-script-tty-stdin
May 6, 2026
Merged

LLM-1521: reattach stdin to /dev/tty when piped#50
castabar merged 2 commits into
mainfrom
fix/install-script-tty-stdin

Conversation

@castabar
Copy link
Copy Markdown
Contributor

@castabar castabar commented May 5, 2026

Fixes

1. Install script: API key prompt fails when piped (curl | bash)

When installing Kimchi via curl ... | bash, stdin is a pipe from curl and is already at EOF. This caused the first-run API key prompt to immediately fail with error: read API key: EOF.

Fix in scripts/install.sh: Redirect kimchi's stdin from /dev/tty when the script detects it is running in a non-TTY context, so the interactive prompt still works. If no TTY is available, skip auto-launch and print a helpful message.

2. OpenClaw setup: refuses to overwrite existing model entries (closes #51)

When Kimchi sets agents.defaults.models (and agents.defaults.model.fallbacks) via OpenClaw's config set CLI, OpenClaw defaults to replace mode and refuses because the user already has other entries (e.g., openai-codex/gpt-5.4).

Error before:

Refusing to replace agents.defaults.models; it would remove existing entries: openai-codex/gpt-5.4. Use --merge to merge

Fix in internal/tools/openclaw.go:

  • Batch JSON path: Split batch to only cover non-conflicting fields (provider block + primary). Use separate openclaw config set --merge calls for fallbacks and models.
  • Sequential CLI path: Add --merge flag for agents.defaults.model.fallbacks and agents.defaults.models.
  • Direct file-writing path: Merge into existing defaults["models"], merge into existing defaults["model"] map (preserving keys like temperature, max_tokens), and append Kimchi fallbacks to existing fallbacks array.

Co-Authored-By: Kimchi noreply@kimchi.dev


Kimchi Summary

What changed

Fixes the install script to handle piped execution (e.g., curl | bash) by redirecting input from /dev/tty when stdin is not a TTY. Also updates OpenClaw configuration logic to merge new Kimchi model settings with existing user configuration instead of overwriting.

Why

Piped installation failed when Kimchi required interactive input because stdin was attached to the pipe rather than a terminal. Additionally, registering Kimchi models previously overwrote existing OpenClaw settings like temperature, max_tokens, or custom model fallbacks.

Key changes

  • scripts/install.sh: Added TTY detection—executes kimchi directly if stdin is a TTY, falls back to /dev/tty redirection if available, or prompts the user to run manually otherwise.
  • internal/tools/openclaw.go:
    • Added --merge flag to openclaw config set calls for agents.defaults.model.fallbacks and agents.defaults.models to preserve existing entries.
    • Modified writeOpenClawViaCLI to handle merge-required fields in separate CLI calls outside of --batch-json.
    • Updated writeOpenClawDirect to merge into existing model configuration (preserving keys like temperature) and append to existing fallbacks arrays rather than replacing them.
    • Changed writeOpenClawDirect to merge into the existing models catalog instead of creating a new map.

Impact

  • Breaking changes: None.
  • Configuration: Existing OpenClaw user settings (e.g., temperature, custom fallbacks) are now preserved when registering Kimchi models.
  • Installation: The install script now supports piped execution on systems with /dev/tty access.

When installing Kimchi via 'curl ... | bash', stdin is a pipe from
curl and is already at EOF. This caused the first-run API key prompt
to immediately fail with 'error: read API key: EOF'.

Redirect kimchi's stdin from /dev/tty when the script detects it is
running in a non-TTY context, so the interactive prompt still works.
If no TTY is available, skip auto-launch and print a helpful message.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
@kimchi-review
Copy link
Copy Markdown

kimchi-review Bot commented May 5, 2026

Kimchi Code Review

Property Value
Commit 4c787e6
Author @castabar
Files changed 0
Review status Completed
Comments 0
Duration 20s

Summary

📊 Review Score: 95/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No automated tests are visible for the shell script changes. This is typical for install scripts, though manual testing across different execution contexts (direct execution, piped curl, SSH without TTY) would verify the TTY detection logic.

No significant issues found. LGTM! 🎉

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @kimchi review — re-trigger a full review on the latest commit
  • @kimchi summary — regenerate the PR summary
  • @kimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

@castabar castabar changed the title fix(install.sh): reattach stdin to /dev/tty when piped LLM-1521: reattach stdin to /dev/tty when piped May 5, 2026
Copy link
Copy Markdown

@kimchi-review kimchi-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Review Score: 95/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No automated tests are visible for the shell script changes. This is typical for install scripts, though manual testing across different execution contexts (direct execution, piped curl, SSH without TTY) would verify the TTY detection logic.

No significant issues found. LGTM! 🎉

OpenClaw's config set defaults to replace mode, which causes
the setup to fail when users already have model entries in
agents.defaults.models or agents.defaults.model.fallbacks.

Changes across all three code paths:

1. Batch JSON mode (writeOpenClawViaCLI):
   - Split batch to only cover non-conflicting fields
     (provider block + primary).
   - Use separate openclaw config set --merge calls for
     agents.defaults.model.fallbacks and agents.defaults.models.

2. Sequential CLI mode (writeOpenClawViaCLISequential):
   - Add --merge flag for agent.defaults.model.fallbacks.
   - Add --merge flag for agent.defaults.models.

3. Direct file-writing mode (writeOpenClawDirect):
   - Merge Kimchi model catalog into existing defaults["models"]
     instead of replacing it entirely.
   - Merge into existing defaults["model"] map instead of
     overwriting, preserving keys like temperature and max_tokens.
   - Append Kimchi fallbacks to existing fallbacks array.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
@castabar castabar mentioned this pull request May 5, 2026
@castabar castabar merged commit 4789d11 into main May 6, 2026
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Openclaw kimchi setup config does not work

2 participants