Skip to content

Refactor terminal API to support incremental output streaming#162

Merged
na-trium-144 merged 5 commits intorepl-async-outputfrom
copilot/update-terminal-api-to-async
Feb 7, 2026
Merged

Refactor terminal API to support incremental output streaming#162
na-trium-144 merged 5 commits intorepl-async-outputfrom
copilot/update-terminal-api-to-async

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

The terminal API required collecting all outputs into arrays before passing to addReplOutput() and setExecResult(), despite outputs being available incrementally from the runtime.

API Changes

REPL outputs:

  • addReplCommand(terminalId, command) creates command entry, returns commandId
  • addReplOutput(terminalId, commandId, output) appends single output to command
  • commandId field added to ReplCommand interface (optional for compatibility)

Execution outputs:

  • clearExecResult(filename) clears outputs before execution
  • addExecOutput(filename, output) appends single output to execution result
  • Replaces setExecResult(filename, output[])

Usage Example

Before:

const outputs: ReplOutput[] = [];
await runCommand(cmd, (output) => {
  outputs.push(output);
});
addReplOutput(terminalId, command, outputs);

After:

const commandId = addReplCommand(terminalId, command);
await runCommand(cmd, (output) => {
  addReplOutput(terminalId, commandId, output);
});

Implementation Notes

  • commandId generated as simple sequential counter per terminalId (0, 1, 2, ...)
  • Command lookup uses findIndex() on commandId for correctness over performance optimization
  • Counter is reset when pathname changes along with other terminal data
  • Removes TODO comments about API limitations in repl.tsx and exec.tsx
Original prompt

app/terminal/embedContext.tsxのAPIを非同期処理に対応したい。現在は addReplOutput(terminalId, command, output)setExecResult(filename, output) でoutputを1つのarrayで渡さなければいけませんが、それを使用する箇所(repl.tsxとexec.tsx)ではoutputは逐次取得できるようになっており、それをわざわざarrayにまとめる必要が生じています。
addReplCommand(terminalId, command) -> commandId
addReplOutput(terminalId, commandId, output) // 複数回呼んで追加可能
clearExecResult(filename) // filenameに関連付けられたoutputをクリア
addExecOutput(filename, output) // 複数回呼んで追加可能
のようなAPIに変更してください。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 6, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 7819c2f Commit Preview URL

Branch Preview URL
Feb 07 2026, 03:33 AM

Copilot AI and others added 2 commits February 6, 2026 18:24
…ands by ID

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
Copilot AI changed the title [WIP] Update API for async processing in embedContext Refactor terminal API to support incremental output streaming Feb 6, 2026
Copilot AI requested a review from na-trium-144 February 6, 2026 18:26
(terminalId: TerminalId, command: string, output: ReplOutput[]) =>
const addReplCommand = useCallback(
(terminalId: TerminalId, command: string): string => {
const commandId = `${terminalId}-${Date.now()}-${Math.random()}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot commandIdはterminalIdごとにシンプルな連番にしてください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commandIdをterminalIdごとの連番(0, 1, 2, ...)に変更しました。(7819c2f)

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
Copilot AI requested a review from na-trium-144 February 7, 2026 03:30
@na-trium-144 na-trium-144 marked this pull request as ready for review February 7, 2026 07:12
@na-trium-144 na-trium-144 merged commit 01b44fb into repl-async-output Feb 7, 2026
1 check passed
@na-trium-144 na-trium-144 deleted the copilot/update-terminal-api-to-async branch February 7, 2026 07:12
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.

2 participants