TUI Channeldoc/{zh,en}/design/tui-channel.md

Terminal Channel: Context, Connections and Files

Status: design, 2026-12-04; the owner decided the questions of section 6 the same day. Nothing here is built. This document says how a run started from orquelo tui gets its context

Status: design, 2026-12-04; the owner decided the questions of section 6 the same day. Nothing here is built. This document says how a run started from orquelo tui gets its context, how a local and a remote terminal differ, and how files move in both directions. Section 6 records the owner's decisions. Related: terminal UI · client protocol · context assembly · sigils · ADR 0012.

1. The terminal is a connection, not a plugin

The Host keys a run's context by connection: the channel name, reply_format, the locale, which directives are visible (allow_paths), the session and its history, and where replies are delivered. A plugin is only where those defaults come from.

The TUI speaks httpapi v2, so it needs no Transport plugin of its own. It gets its own httpapi connections, separate from the app's, so its context can say "terminal" without a client branch in the Host:

ConnectionListenerWhoallow_pathsDefault
terminalloopback onlythe local operator, through the local credential (terminal UI 6.4)onon in every new configuration
terminal-remotethe network address the operator choosespaired devices (ADR 0015)offoff; the operator turns it on

They are two connections because allow_paths must differ. A path a local TUI sends names a file on the Host's own disk; one from a remote TUI names a file on another machine, which the Host cannot read.

What is built today and what is missing:

  • ◆Channel name: channel is the transport plugin's name (internal/host/engine/situation.go), so a terminal run would say httpapi. Gap C1.
  • ◆Reply format: httpapi's manifest says "Markdown text to an API client" for every instance. Gap C2.
  • ◆Already per connection: allow_paths (internal/config), session_scope, the connection's locale, and the directive rules of sigils section 7.

2. What a terminal run's context holds

FactLocal terminalRemote terminal-remoteSource
channelterminalterminalC1
reply_formatTerminal Markdown, about 100 columns, files saved on the person's machine (section 2.1)the sameC2
questionsA question opens a dialog where the run stopped; it is also shown in the person's other linked channelsthe samethe transport's QuestionPolicy, which httpapi answers from an instance option (C2)
Chatdirect; chat_id is the conversationthe samebuilt
SenderThe local operator, the console's local userThe paired device's userbuilt: static token, pairing
WorkspaceThe directory orq started in (workspace.path), if the workspace policy allows itThe Host's workspace for the conversation: a named workspace or scratch; never a path on the clientbuilt: WorkspaceRequest, allow_paths
OS, shell, pathsThe machine the person sits at, which is the Host'sThe Host's, which the context says plainlybuilt: the workspace provider's environment item
Instruction filesThe repository's instruction files, by the existing project rule (listed, read before working there)The same, for the Host's checkoutbuilt: instruction_files_not_shown, P83
LocaleThe terminal's language (LANG, or Windows' UI language) as the explicit request preferencethe samegap C3
Time zoneThe client machine's zonethe samegap C3
HistoryThe session of (terminal, conversation): history, summaries, compaction, /new, /compact, as on every channelthe samebuilt
MemoryThe person's memories; shared with Feishu and the app once the accounts are linked (orquelo identity link terminal:local feishu:<id>)the samebuilt: ADR 0012, memory scopes
Directives/, @, $, and ! for the owner, since allow_paths is on/, @, $; no !built: sigils section 7

Locale and time zone are separate facts: neither is inferred from the other, and neither changes the person's identity or grants.

2.1 Reply format

The terminal and terminal-remote instances set it as an instance option (C2):

Replies are shown in a terminal about 100 columns wide that renders Markdown: headings, bold, lists, code blocks and tables. Keep tables narrow, and send wide ones as files. Images do not show inline; send them as files, which are saved on the person's computer. Links are shown as text the person can open.

2.2 Conversations and workspaces

  • ◆orq starts a new conversation. Its id is made by the TUI, and httpapi keeps a device's conversations under <user>: as it does today.
  • ◆A conversation is bound to the workspace of its first message. Starting orq in another directory starts another conversation.
  • ◆orq -c continues the latest conversation whose workspace is the current directory. That needs /v1/conversations to report each conversation's workspace and take ?workspace= (C4).

2.3 Other channels' conversations

The picker and the inbox list the person's conversations on every linked channel, as built.

  • ◆Follow. Opening a Feishu conversation follows its runs and answers its questions, read-only. A message typed there is not posted to Feishu: the TUI's messages belong to its own connection.
  • ◆Continue here. Ctrl+N on a followed conversation starts a terminal conversation that carries the other conversation's recent turns as its channel context (<orq:chat>, built for the Feishu twin's threads). Only conversations of the same person can be carried (C6).

3. Local and remote

ConcernLocalRemote
Finding the Hostdata/local-client.json; started when downorq -host URL; never started
AuthenticationPer-start local token, owner-only file, no pairingPaired-device token; revoking the device closes its streams
Transporthttp://127.0.0.1:<port>, plain HTTP on loopbackHTTPS required; plain HTTP only to loopback addresses
WorkspaceThe current directoryThe Host's workspace for the conversation
@ file mentionsThe local file indexOff. The Host's files are reached through the agent's tools, not by mention
Sending filesPath or upload (section 4.1)Upload only
Receiving filesDownload to the local folder (section 4.2)The same, resumable (C7)
ChangesThe checkout on this machine: real files, the diff in the TUIThe Host's checkout: the diff in the TUI; applying it locally is the person's choice (d saves a patch file)
! shellFor the owner, as in the consoleNot offered
ClipboardThe system clipboardOSC 52, through SSH and the terminal
Losing the linkHost restart: banner, replay, draft keptThe same, with back-off; a revoked device ends with a clear notice and no retry

4. Files

4.1 From the person to a run

  • ◆A file inside the workspace (local). It is not copied. The message names the path, and the run reads it where it is (C5). The chip shows "in workspace".
  • ◆Any other file (local), a pasted image, or anything on a remote terminal. It is uploaded through the resumable upload of the client protocol, then attached by upload_id.
  • ◆Each chip shows its own progress. A cut connection resumes from the last byte received.
  • ◆A file over upload_max_mb is refused before any byte is sent.
  • ◆A file is attached when its upload completes. Sending before then waits for it, and the message never goes out with a half file.
  • ◆A dropped path. Terminals paste a dropped file as its path. The TUI turns a path that names a readable file into a chip; anything else stays text.
  • ◆Attachments start a run. A message with files starts a new run queued behind the active one, as on every channel (ADR 0006); text alone steers.

4.2 From a run to the person

  • ◆Delivered files. The run's artifacts reach the terminal connection as file messages (message.created with file). The TUI saves each one to <download folder>/orquelo/<conversation>/<run>/<name> and shows it with o open, c copy path, s save into the workspace.
  • ◆The download folder is the system's Downloads folder unless the person sets another in the TUI's own settings.
  • ◆Names are cleaned (no path separators, no .., no control characters). An existing file is never overwritten: the next free name name (2).ext is used.
  • ◆Files are only opened with the system's default app on o, and never run.
  • ◆Size. Files up to 20 MB are saved as they arrive. Larger ones show their size and wait for d. Downloads resume with Range after a cut (C7).
  • ◆When the TUI was closed. History replays the file messages, and the TUI fetches the files when it shows them. Nothing is lost by detaching.
  • ◆Delivery is the Host's, saving is the TUI's. A file message counts as delivered when it is stored for the connection, as for every channel. A failed save on the person's machine is retried by the TUI from /v1/artifacts/{id}. It never reruns the run and never changes the delivery's state.
  • ◆Files changed in the workspace are not artifacts. They are already where the run wrote them, and the TUI shows them as the run's changes (/v1/runs/{id}/diff).

5. Host gaps

#GapProposal
C1channel is the plugin's nameAn optional transport interface, ChannelKind() string, beside SelfIdentifier; httpapi answers with an instance option channel (terminal). Generic: any instance can name its kind
C2One reply_format for every httpapi instance, and no questions texthttpapi implements the existing ReplyFormatter and QuestionPolicy from instance options reply_format and questions
C3No locale or time zone from the personPOST /v1/messages takes locale (BCP 47) and timezone (IANA). Locale becomes the explicit request preference of the locale contract; the time zone replaces the agent's default in the run's baseline. Both are validated, and neither is trusted for identity
C4Conversations do not show their workspace/v1/conversations returns workspace and accepts ?workspace=
C5Attachments are uploads onlyattachments: [{path}] accepted only on a connection with allow_paths, for files the workspace policy lets the run read; refused elsewhere with attachment.path_not_allowed
C6No context from another channel's conversationcontext_from: {connection, conversation} on POST /v1/messages: the Host fills the event's channel context from that conversation's recent turns when it belongs to the same person, else conversation.unknown
C7Artifact downloads cannot resumeGET /v1/artifacts/{id} honours Range

C1 adds an optional plugin interface, so it needs an ADR, which can share one with G1 of the terminal UI. None of the gaps adds a client branch to the Host.

6. Owner decisions

Decided 2026-12-04:

  • ◆Every new configuration ships terminal; terminal-remote is off by default.
  • ◆Delivered files go to the system's Downloads folder, under orquelo/<conversation>/<run>/.
  • ◆A delivered file over 20 MB waits for d.
  • ◆"Continue here" (C6) carries a followed conversation's recent turns into a new terminal conversation.

7. Verification

When built:

  • ◆Interface cases on terminal: context fields (channel, reply format, locale, time zone, workspace); ! visible locally and refused remotely; a path attachment accepted locally and refused remotely.
  • ◆A real-model e2e case through the TUI (PTY) with an uploaded file and a delivered file saved locally.
  • ◆A failure case: a download cut mid-file resumes, and the run is not repeated.