jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Feature: opt-in inline completion provider for the composer (dim ghost text, Tab accepts)

Open elcodabra opened this issue 1 month ago • 1 comments

Problem

There is no way for a local tool to suggest text while the user types in the jcode composer. Tab completes only /commands and skills (App::autocomplete), the @-file work (#570, #934) is a picker, and hooks fire on turns and tools, not on edits.

The use case is word completion and next-word prediction. For example, Terminal T9 (mine, not public yet) completes words from dictionaries and from what the user has typed before. It already runs as dim ghost text with Tab in Claude Code, OpenCode, zsh and bash.

Typed:       please refact
Ghost text:               or
After Tab:   please refactor

In jcode today it only works blind: [dictation] runs a command on a key, the command reads the draft over the debug socket (client:state) and prints a suffix to insert. It works, but there is no preview. It also needs ~/.jcode/debug_control, which lets any local process read and change the input. And on macOS with a non-US layout only a Ctrl key reaches it (#1042 is related).

Proposal (minimal, opt-in)

[completion]
command = ""        # empty (the default): feature off, nothing spawned
timeout_ms = 50     # a reply later than this is dropped

Protocol. One long-lived process per TUI client, started lazily on the first edit after the feature is enabled. JSON lines on stdin/stdout, so there is no process spawn per keystroke:

// jcode → provider, after each edit or cursor move (debounced, ~30 ms)
{"id": 7, "text": "please refact", "cursor": 13, "cwd": "/repo"}   // cursor: UTF-8 bytes, as cursor_pos
// provider → jcode
{"id": 7, "insert": "or"}    // or {"id": 7} for no suggestion

Only the reply to the latest id is used. Submitted prompts are already in prompt-history.jsonl, so learning needs nothing new.

Rendering. The insert text is drawn dim right after the cursor, and only when the cursor is at the end of its line, which keeps the renderer change small. The suggestion is never shown while a slash or @ popup, a picker or an overlay is open. Any edit or cursor move clears it until the next reply.

Keyboard precedence (only while a suggestion is shown):

  1. Pickers, overlays and the slash/skill popup keep their keys.
  2. Tab accepts the suggestion only when autocomplete() has nothing to do (no / token under the cursor); otherwise Tab is unchanged.
  3. → accepts it only with the cursor at the end of the input. Elsewhere it moves the cursor as now.
  4. Enter, Esc and all other keys behave exactly as today. Accepting is one undo step (insert_input_text).

Privacy and cost. Off by default. jcode itself makes no network calls for this. The draft goes only to the user-configured local process, which is the same trust level as hooks. No model calls and no KV-cache impact.

Deterministic fallback. No command, a spawn failure, a crash, a malformed line or a reply over timeout_ms all mean no suggestion, and every key does exactly what it does today. A crashed provider is restarted at most once a minute and the error is logged once.

Implementation sketch

  • crates/jcode-config-types: CompletionConfig { command, timeout_ms }.
  • crates/jcode-tui: a small provider task (spawn, request/response channel, stale-id drop); ghost: Option<String> in app state, set on reply and cleared on edit; drawn in ui_input.rs; Tab/→ checks in input.rs and remote/key_handling.rs, after the popup handling.
  • Tests: protocol (stale ids, timeout, malformed lines); keys (Tab with and without a / token, → mid-line); rendering at end of line only.

If this shape fits, I'm happy to send a focused PR for it. If a narrower first step is preferred (for example, only a documented provider protocol, or ghost text without →), that works too.

elcodabra avatar Oct 21 '26 09:10 elcodabra

Thanks! This adds a new subprocess protocol and config surface, so it's flagged for a maintainer design decision.

--- — Jcode agent (automated triage), on behalf of @1jehuang

1jehuang avatar Oct 21 '26 22:10 1jehuang