Skip to content

fix(tui): detect Orca image support - #2454

Closed
XRX193 wants to merge 1 commit into
MoonshotAI:mainfrom
XRX193:fix/orca-inline-images
Closed

XRX193 wants to merge 1 commit into
MoonshotAI:mainfrom
XRX193:fix/orca-inline-images

Conversation

@XRX193

@XRX193 XRX193 commented Jul 31, 2026

Copy link
Copy Markdown

Related Issue

No Kimi issue. This completes client-side compatibility for stablyai/orca#11668 and stablyai/orca#11706.

Problem

Orca exports TERM_PROGRAM=Orca and is adding Kitty graphics support, but Kimi Code treats it as an unknown terminal and falls back to text instead of displaying inline images.

What changed

  • Recognize Orca as supporting Kitty inline images, true color, and OSC 8 hyperlinks.
  • Preserve the existing tmux and screen precedence.
  • Add a regression test and package/CLI changesets.

Tested with pnpm --filter @moonshot-ai/pi-tui test (716 passing) and pnpm --filter @moonshot-ai/pi-tui typecheck.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d82fb53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/pi-tui Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78e23ae82b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/terminal-image.ts Resolved
@XRX193

XRX193 commented Sep 29, 2026

Copy link
Copy Markdown
Author

Refreshing this with the upstream dependency now resolved: the Orca-side capability advertisement has landed.

stablyai/orca#19512 merged on 2026-09-18 (09073086a8) and exports ORCA_IMAGE_PROTOCOL=kitty on all three PTY spawn paths — daemon subprocess, local provider, and relay handler — with the variable forwarded across the WSL boundary. That's the signal this PR gates on, and the contract is unchanged: images stay off unless both TERM_PROGRAM=Orca and ORCA_IMAGE_PROTOCOL=kitty are present, so Orca releases predating #19512 keep the text fallback rather than reserving blank image rows.

That closes the loop on the concern raised in the earlier review — the gating is on a capability Orca now actually advertises, not on an open upstream PR.

Branch state: still mergeable against current main, no conflicts. Happy to rebase or narrow the scope if the maintainers would prefer this routed differently. The equivalent change is also proposed for the sibling TUI in earendil-works/pi#9329.

@XRX193
XRX193 force-pushed the fix/orca-inline-images branch from d92fbd7 to 6b47eee Compare October 29, 2026 07:02
@XRX193

XRX193 commented Oct 29, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (89e07b81). Head is now 6b47eee9, one commit, mergeable again.

The conflict was structural, not semantic. packages/pi-tui/src/terminal-image.ts gained two outer-terminal detectors at exactly the slot this branch inserts its Orca check:

  • #10573 — herdr
  • #11131 — rex

The Orca check now sits after rex and still ahead of the KITTY_WINDOW_ID branch, for the same reason as the others: that variable can leak into Orca panes, so first-match wins has to reach the explicit-capability block before the ambient one. detectCapabilities keeps its exported name — only the internal helper was renamed to detectCapabilitiesFromEnvironment, so the test file needed the new env key and nothing else.

Diff is a pure addition, +32/-0 across 4 files: one source block (+6), two tests plus the env key (+16), and two changesets (+5 each).

Verification — full packages/pi-tui suite at this head, Windows 11 / Node 22.22.2:

node --test test/*.test.ts
# tests 1145   # pass 1139   # fail 5   # skipped 1

All 5 failures reproduce identically on unmodified 89e07b81 (1143 / 1137 / 5), so none are introduced here:

  • Linux ARM64 prebuild supports 64 KB system pages
  • uses the native platform helper directly as the clipboard API
  • Linux loads X11 lazily and rechecks DISPLAY
  • imageFallback → 2 cases, hardcoded POSIX path separators on Windows

The two new Orca cases pass: TERM_PROGRAM=Orca alone stays images: null; with ORCA_IMAGE_PROTOCOL=kitty it resolves to kitty plus hyperlinks.

Still zero required check runs on this fork head, so GitHub reports blocked — the only remaining gate is a maintainer triggering CI.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b47eee96f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/terminal-image.ts Outdated

// Orca advertises Kitty graphics support through ORCA_IMAGE_PROTOCOL. Check it before
// outer-terminal detection because variables like KITTY_WINDOW_ID can leak into its panes.
if (termProgram === "orca" && process.env['ORCA_IMAGE_PROTOCOL'] === "kitty") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add an upstream intent card for Orca detection

This adds a new local capability-detection behavior to the vendored fork, but the commit leaves packages/pi-tui/UPSTREAM.md unchanged and none of its existing intent cards covers Orca image detection. The next upstream reconstruction therefore has no decision/why-not-in-app record telling maintainers to preserve this branch; add the mandatory intent card alongside the test before landing.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L11-L17

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T11:31:56.665517Z d82fb53 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@XRX193
XRX193 force-pushed the fix/orca-inline-images branch from 6b47eee to 59dc06b Compare October 31, 2026 07:13
@XRX193

XRX193 commented Oct 31, 2026

Copy link
Copy Markdown
Author

Heads-up after the latest review pass: head is now 59dc06b6, diff is +38/-0 across five files, one commit.

Intent card added. The P1 on terminal-image.ts was correct — this changes vendored-fork behavior and packages/pi-tui/UPSTREAM.md had no card for it. There is now an orca-image-detection — keep card recording the decision and why it cannot live in apps/kimi-code/src/tui: the only app-side levers are PI_IMAGE_PROTOCOL and setCapabilityOverrides, and both apply after detection, so either one would also override the tmux/screen image opt-out. Keeping that opt-out means the env-gated branch belongs in the detector.

Upstream state. earendil-works/pi#9329 merged the same detector on 2026-10-29 (merge f09d01b8). The fork's Last Sync Point is still 7c22a93 (2026-10-22), so the patch is still needed at the current pin, but it becomes redundant as soon as the pin moves past that commit. If you would rather take this through the next upstream sync than through this PR, say so and I will close it — the card keeps the intent documented either way.

The only change since 6b47eee9 is that documentation file, so the node --test result reported for the previous head still applies.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59dc06b6af

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/terminal-image.ts Outdated

// Orca advertises Kitty graphics support through ORCA_IMAGE_PROTOCOL. Check it before
// outer-terminal detection because variables like KITTY_WINDOW_ID can leak into its panes.
if (termProgram === "orca" && process.env['ORCA_IMAGE_PROTOCOL'] === "kitty") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop unadvertised Orca from reaching outer detectors

When an older Orca sets TERM_PROGRAM=Orca but lacks ORCA_IMAGE_PROTOCOL while inheriting KITTY_WINDOW_ID (the leak anticipated by the new comment and intent card), this positive-only check is skipped and the following Kitty detector still returns images: "kitty", causing unsupported releases to emit image escapes and reserve blank rows instead of using the promised text fallback. The fresh evidence in this revision is the fallthrough from this new condition into the unchanged KITTY_WINDOW_ID branch; handle Orca as a terminal-level branch that keeps images disabled when the advertisement is absent, and cover the leaked-variable case in the regression test.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L3-L5

Useful? React with 👍 / 👎.

@XRX193
XRX193 force-pushed the fix/orca-inline-images branch from 59dc06b to d7e199a Compare November 1, 2026 07:23
@XRX193

XRX193 commented Nov 1, 2026

Copy link
Copy Markdown
Author

Addressed the Codex P2 finding on the Orca fallback. New head d7e199a1, rebuilt on main (a2afdbc7); packages/pi-tui was byte-identical between the old base and current main, so the diff is unchanged apart from the fix below. Still a pure addition: 5 files, +50/−0.

The gap: the detector matched TERM_PROGRAM=Orca && ORCA_IMAGE_PROTOCOL=kitty, so an Orca release that sets TERM_PROGRAM but not the advertisement fell through to the KITTY_WINDOW_ID branch. When Orca is started from inside Kitty, that variable is inherited by the pane, the detector reports images: "kitty", and the unsupported release gets escape sequences it renders as blank rows — the exact failure the two-signal gate was meant to prevent, and the opposite of what the previous comment claimed.

Fix — Orca as a terminal-level branch (terminal-image.ts):

if (termProgram === "orca") {
	return process.env['ORCA_IMAGE_PROTOCOL'] === "kitty"
		? { images: "kitty", trueColor: true, hyperlinks: true }
		: { images: null, trueColor: hasTrueColorHint, hyperlinks: false };
}

Without the advertisement the branch returns images: null regardless of leaked outer-terminal variables. trueColor/hyperlinks there mirror the pre-existing unknown-terminal outcome for such a release, so the only behavior change is the leak case itself.

Regression test (new case in detectCapabilities): TERM_PROGRAM=Orca + KITTY_WINDOW_ID=1 must stay at images: null. Verified it discriminates — under the previous positive-only condition that test fails (kitty), under this head it passes.

Verification on Windows, Node 22.22.2, node --test against a local checkout:

Tree Tests Pass Fail
main a2afdbc7 1145 1139 5
this head 1146 1140 5

Same five failures on both sides (Linux ARM64 prebuild, native clipboard helper, X11 lazy load, two imageFallback POSIX-separator cases), i.e. no regression. The packages/pi-tui/UPSTREAM.md intent card now records the terminal-level branch instead of the two-signal conjunction.

One parity note: upstream earendil-works/pi (merged f09d01b8) still uses the positive-only form, so this fork diverges by one condition until the next sync. If you'd rather keep the fork byte-comparable to upstream, I can send the same guard upstream first and hold this PR — say the word and I'll take that route instead.

@XRX193
XRX193 force-pushed the fix/orca-inline-images branch from d7e199a to a89e43e Compare November 6, 2026 08:38
@XRX193

XRX193 commented Nov 6, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (e2770e37); head is now a89e43ec, still one commit, mergeable again.

Why it went dirty: the conflict was not in the detector. Upstream #4618 (e6ae8ed4) appended a shared-animation-frames section to packages/pi-tui/UPSTREAM.md — the same end-of-file slot this PR appends orca-image-detection to. Two pure appends at the same anchor, nothing semantically incompatible.

Resolution: both sections kept, in upstream order (shared-animation-frames, then orca-image-detection). src/terminal-image.ts, the test file, and both changesets are byte-identical to the previous head — the diff stays +50/-0 across 5 files, so the earlier review points still apply unchanged.

Regression check (node --test test/terminal-image.test.ts, Node 22.22, Windows):

tree tests pass fail
main e2770e37 80 78 2
a89e43ec 83 81 2

The failing set is identical on both sides — the imageFallback cases that assume POSIX path separators fail on Windows regardless of this patch. The three added tests (Orca advertised, Orca with a leaked KITTY_WINDOW_ID, Orca without the advertisement) pass.

Nothing in packages/pi-tui changed between the previous rebase and today apart from UPSTREAM.md, so there is no behaviour change to re-review here.

Orca sets TERM_PROGRAM=Orca, which no branch recognises, so inline images
fell back to the text placeholder. Orca supports the Kitty graphics protocol
but only advertises it out-of-band via ORCA_IMAGE_PROTOCOL; require both
signals so releases predating that advertisement keep the text fallback
instead of reserving image rows nothing renders.

The check sits with the other outer-terminal detectors, ahead of the
KITTY_WINDOW_ID branch, because that variable leaks into Orca panes.
@XRX193
XRX193 force-pushed the fix/orca-inline-images branch from a89e43e to d82fb53 Compare November 12, 2026 11:29
@XRX193

XRX193 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Rebased onto main @ f407c52e (v-next after the 2026-11-12 release sync); head is now d82fb53a, still one commit, mergeable again.

Why it went dirty. Two separate upstream changes landed in packages/pi-tui in the last two days, and only one of them actually collided:

terminal-image.ts itself was byte-identical between my old base and main (9a72c493 on both sides), so the detector never needed a change.

How it was resolved. Upstream's sentence wins, the card follows it — nothing from #4843 was dropped and nothing of mine was duplicated. The rebase also carries #4746's consolidation: the head's test file is upstream's rewritten version plus the three Orca cases, not a revert to the pre-consolidation file.

Verification (packages/pi-tui/test/terminal-image.test.ts alone, Node 22.22.2, Windows):

Tree tests pass fail
main @ f407c52e 64 62 2
this head 67 65 2

The two failures are identical on both sides and are the imageFallback cases that build POSIX paths (shortens home-prefixed absolute paths without hyperlinks, wraps shortened absolute paths in OSC 8 links) — a Windows path-separator artefact, present on main before this branch.

The three new cases are not tautological: with the whole tree unchanged except for dropping the Orca branch, two of them go red (…when Kitty variables leak in and …advertising Kitty support), while the third stays green by design because TERM_PROGRAM=Orca already yields images: null on main.

No approval existed on the previous head, so the force-push discarded nothing.

@XRX193

XRX193 commented Nov 26, 2026

Copy link
Copy Markdown
Author

Superseded by the pi-tui v1.6.1 sync — closing

main @ 8f794b00 now ships Orca detection, landed today in 79dc02a9 (feat(pi-tui): sync upstream pi-tui to v1.6.1 (#5462)). That sync pulls the earendil-works/pi tree at b882d08f (2026-11-25), i.e. the upstream side of this change (pi#9329, merged 2026-10-29) is now vendored verbatim, so this fork no longer needs to carry it.

In packages/pi-tui/src/terminal-image.ts (L100–105) on main:

// Orca supports Kitty graphics but only advertises it through ORCA_IMAGE_PROTOCOL. Require
// both signals so Orca releases predating that advertisement keep the text fallback instead
// of reserving image rows that nothing renders.
if (termProgram === "orca" && process.env['ORCA_IMAGE_PROTOCOL'] === "kitty") {
	return { images: "kitty", trueColor: true, hyperlinks: true };
}

And the regression cases arrived with it, in packages/pi-tui/test/terminal-image.test.ts:

  • L267 it("keeps images disabled for Orca without an image capability signal")
  • L274 it("enables images and hyperlinks for Orca advertising Kitty support")

So the behaviour this PR argued for — recognize Orca, and gate images on the capability advertisement rather than on TERM_PROGRAM alone — is on main with tests. The remaining 5-file +50/−0 diff is redundant, and being parked on the same insertion slot is why the PR just flipped to dirty.

One delta worth recording, in case it matters to you later: main gates with a conjunction, so TERM_PROGRAM=Orca without the advertisement still falls through to the KITTY_WINDOW_ID check and resolves to images: "kitty" when that variable is inherited (e.g. Orca launched from inside kitty). That is the Codex P2 raised in this thread; the new main test covers TERM_PROGRAM=Orca alone, not with KITTY_WINDOW_ID set. Hardening it belongs upstream in earendil-works/pi — it would flow here on the next sync — not in the vendored fork.

Closing as done. Happy to reopen if you would rather land the fork-side variant instead.

@XRX193 XRX193 closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant