Skip to content

Add support for OSC777 (Send Notification) - #20012

Merged
Carlos Zamora (carlos-zamora) merged 22 commits into
mainfrom
dev/cazamor/toast/osc777
Jun 4, 2026
Merged

Carlos Zamora (carlos-zamora) merged 22 commits into
mainfrom
dev/cazamor/toast/osc777

Conversation

@carlos-zamora

Copy link
Copy Markdown

Summary of the Pull Request

targets #20010

This adds support for the OSC 777 ; notify ; title ; body ST sequence. This allows client applications to send a notification to the Terminal. When this notification is clicked, it summons the terminal window that sent it.

Validation Steps Performed

# in PowerShell. Terminal should not be focused.
sleep 2; Write-Output "`e]777;notify;Hello;This is a notification`a"

PR Checklist

Heavily based on #19938
Co-authored by Mike Griese (@zadjii-msft)

Comment thread src/terminal/adapter/adaptDispatch.cpp Resolved
Comment thread src/terminal/adapter/adaptDispatch.cpp Resolved
@github-actions

This comment has been minimized.

## Summary of the Pull Request
Targets #20010 

Manually assign an AUMID to our process when we're running unpackaged.
Main difference from #19937 is what AUMID we use. Before, it was per
branding, but the `WindowEmperor` already appends an exe path hash for
unpackaged instances to prevent crosstalk. Here, we're just using the
same pattern: `Microsoft.WindowsTerminal.<hash>`.

Heavily based on #19937
Co-authored by @zadjii-msft
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 4, 2026
@carlos-zamora

Copy link
Copy Markdown
Author

Feedback from Bug Bash (5/5)

  • should be disabled by default

Dustin L. Howett (@DHowett) Got a reason why? Is it that we just don't want applications to spam the user with notifications?

@carlos-zamora

Copy link
Copy Markdown
Author

Updated default to false.

Validated that this works. Can be tested using:

Write-Host "$([char]27)]777;notify;Title;Message$([char]27)\"

Comment on lines +2790 to +2794
"compatibility.allowOSC777": {
"default": false,
"description": "When set to true, applications can send OSC 777 escape sequences to trigger desktop toast notifications with a custom title and body.",
"type": "boolean"
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fwiw i discovered today that there's also osc 9

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You also discovered that six years ago in #7718 (comment). 😁

<comment>{Locked="OSC 52"}{Locked="Manipulate Selection Data"}Header for a control to toggle support for applications to change the contents of the Windows system clipboard.</comment>
</data>
<data name="Profile_AllowOscNotifications.Header" xml:space="preserve">
<value>Allow OSC 777 (Desktop Notification) to show toast notifications</value>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

future us todo: when we add support for the other OSC strings for notifying, this string will need to get updated

@carlos-zamora
Carlos Zamora (carlos-zamora) dismissed Dustin L. Howett (DHowett)’s stale review June 4, 2026 00:53

Applied feedback. Review is old/stale. Got two approvals.

If there's any more feedback, happy to fix it after this merges.

@carlos-zamora
Carlos Zamora (carlos-zamora) merged commit 93bdbfa into main Jun 4, 2026
20 checks passed
@carlos-zamora
Carlos Zamora (carlos-zamora) deleted the dev/cazamor/toast/osc777 branch June 4, 2026 00:54
Takeaki Kobayashi (takecchi) added a commit to takecchi/codiva that referenced this pull request Jul 30, 2026
## 概要

codiva の作業完了通知などのポップアップを**クリックするとスクリプトエディタ(Script
Editor)が開く**不具合を修正しました。通知をクリックしたら codiva を動かしているターミナルに戻れるようになります。

## 原因

macOS の通知センターは通知を**アプリバンドル単位**で管理していて、バンドルを持たないプロセスは通知を出せません。`osascript`
は単体バイナリなので、そこから出した `display notification` は AppleScript の代表バンドル
`com.apple.ScriptEditor2`(= スクリプトエディタ)名義で投函されます。


通知クリックは「送信元アプリをアクティブにする」動作なので、結果としてスクリプトエディタが開いていました(通知の見出しも「スクリプトエディタ」になっていたはずです)。`osascript`
には `terminal-notifier` の `-sender` 相当の指定がなく、`tell application id "…" to
display notification` で端末アプリ名義にする手は TCC(自動化)の許可プロンプトが必要になります。

同じ症状は他の CLI
でも報告されています([opencode#23446](https://github.com/anomalyco/opencode/issues/23446))。

## 対応

**端末自身に通知を出させる OSC シーケンスを優先**し、`osascript` / `notify-send`
は非対応端末向けのフォールバックに落としました。端末エミュレータが投函するので通知は端末アプリ名義になり、クリックでそのターミナルが前面に来ます。OSC
52(クリップボード)と同じ仕組みなので追加依存はなく、SSH / コンテナ越しでも動きます。

| 方言 | 形 | 対応端末 |
|---|---|---|
| OSC 777 | `ESC ] 777 ; notify ; <title> ; <body> BEL` | Ghostty /
WezTerm / foot |
| OSC 9 | `ESC ] 9 ; <body> BEL`(本文1つだけ) | iTerm2 |
| OSC 99 | `ESC ] 99 ; i=<id>:d=0:p=title:e=1 ; <base64> ST` +
`d=1:p=body` | kitty |

### 実装のポイント(レビューで潰した罠)

- **`TERM_PROGRAM` / `TERM` だけに頼らない**: tmux は `TERM_PROGRAM` を `tmux`
で上書きし(tmux 3.2 以降)`TERM` も `screen-*` に化けるため、それだけ見ると **tmux
内では必ず判定漏れして元の症状に戻る**。端末が自前で撒く `GHOSTTY_BIN_DIR` /
`GHOSTTY_RESOURCES_DIR` / `WEZTERM_PANE` / `WEZTERM_EXECUTABLE` /
`KITTY_WINDOW_ID` / `ITERM_SESSION_ID` / `LC_TERMINAL` も見る(`LC_TERMINAL`
は ssh が既定で転送するので、リモートの codiva からでも手元の iTerm2 に出る)。
- **Windows Terminal と urxvt は意図的に判定しない**: WT の通知用 OSC 777 は
`allowOSC777` 設定が既定
false([microsoft/terminal#20012](https://github.com/microsoft/terminal/pull/20012))で、OSC
9 の方は ConEmu 方言の数値サブコマンド専用。urxvt の OSC 777 は同梱されていない perl
拡張へ丸投げする汎用口。OSC は解釈されたか分からないため、誤判定すると**通知が無音で消えて、動いていた OS 通知まで失う**。
- **入力の無害化**: セッションタイトルは LLM がリポジトリ内容から作る非信頼入力なので、制御文字(C0 / DEL / **C1**
— UTF-8 のまま U+009C を ST、U+009B を CSI と解釈する端末がある)を空白へ潰し 120 文字で切る。OSC 777
の title 内 `;` はフィールド境界と誤読されるので `,` へ、OSC 9 は本文が `9;4;70`
のようなプログレスバー指示に化けないよう `;` を全置換。OSC 99 は payload を base64(`e=1`)で運ぶ。
- **OSC 99 の通知 id は `<pid>-<連番>`**: 同じ id の chunk は上書き・連結されるため、1 端末で
codiva を 2 つ動かしても衝突しないように pid を混ぜる。
- 非 TTY のときはエスケープを書かない(通知にならずゴミが残るだけ)。tmux 内は DCS
パススルーで包む(`allow-passthrough on` が必要。`wrapForTmux` を `clipboard.ts` から
`terminal-mode.ts` へ移して共用)。
- stdout への `write` は try/catch で握り潰す(best-effort の契約どおり、端末が閉じられた直後の遷移で
commit 経路を壊さない)。

## 変更ファイル

- `src/utils/notify.ts`: `detectNotifyProtocol` /
`buildNotifySequence`(純関数)を追加し、`notify()` を OSC → OS コマンドの2経路に
- `src/utils/terminal-mode.ts` / `src/utils/clipboard.ts`: `wrapForTmux`
を共通化
- `src/utils/notify.spec.ts`: 端末判定と3方言のシーケンス組み立てをテーブルドリブンで追加(tmux 内・ssh
越し・意図的な非検出・制御文字・切り詰め・write 失敗)
- `README.md` / `docs/ARCHITECTURE.md` / `docs/TECH_NOTES.md` /
`.claude/rules/git-and-io.md`: 挙動と設計判断・実測結果を反映

## テスト

- [x] `npm run lint`
- [x] `npm run typecheck`(このワークツリーでは既存の `marked`
未解決エラーのみ。今回の変更に起因するものなし)
- [x] `src/utils/notify.spec.ts` / `clipboard.spec.ts` 緑(47 テスト)
- [ ] CI での `lint → typecheck → test → build` 全通過
- [ ] 手動確認(TTY 必須): Ghostty で完了通知が「Ghostty」名義で出て、クリックで Ghostty が前面に来ること
- [ ] 手動確認: tmux 内(`allow-passthrough on`)でも同様に通知が出ること
- [ ] 手動確認: Terminal.app ではフォールバック経路で通知が出ること(この経路は従来どおりスクリプトエディタ名義)
@kedia990

Copy link
Copy Markdown

Many thanks for adding this; its working excellently with the canary builds and I've become very dependent on it when running Claude Code in WT :)

Is there an ETA on when this will ship with a Prod release? I assume (hope?) that would be with 1.26, but its not super-clear to me what the timeline on that is anymore. The only thing that I can tell from https://github.com/microsoft/terminal/milestones is that 1.26 is 2 months behind, but the ETA is unclear.

If there's a better place for me to be asking this question (since it's not related to the technical implementation of this feature), please feel free to redirect me. (And thanks again for the effort here!)

@damnskippy

Copy link
Copy Markdown

Should there be a config knob to allow notifications even when Terminal is in focus?
User could be in an active tmux window and may still be interested in getting a notification from an inactive tmux window while Terminal is still in focus the whole time.
Thanks.

@zadjii-msft

Copy link
Copy Markdown
Member

Is there an ETA on when this will ship with a Prod release? I assume (hope?) that would be with 1.26

Good news! https://github.com/microsoft/terminal/releases/tag/v1.26.2734.0 shipped just last Friday ☺️ sorry for the delays

@zadjii-msft

Copy link
Copy Markdown
Member

Should there be a config knob to allow notifications even when Terminal is in focus? User could be in an active tmux window and may still be interested in getting a notification from an inactive tmux window while Terminal is still in focus the whole time. Thanks.

This is actually a perfectly reasonable request. An actually sane use case where it would make sense to show it even if the terminal is in the FG. Making that behavior also opt-in makes sense to me.

I'll convert that comment to an issue.

masseater added a commit to masseater/msa that referenced this pull request Oct 24, 2026
止まったときの知らせ(BEL・OSC 9・OSC 777)が、実際の使い方で届くかを
確かめた。経路は、Windows 機の Windows Terminal から ssh で Mac に入り、
tmux の中で msa を動かす形である。

- Windows Terminal 1.24.11911.0(stable): ソース(adaptDispatch.cpp の
  DoConEmuAction)は OSC 9 の数値の副コマンド(4・9・12)だけを扱い、
  `9;msa: ...` の本文は捨てる。OSC 777 は microsoft/terminal#20012 で入り、
  Preview 1.26 から、プロファイルの `compatibility.allowOSC777`(既定 false)を
  true にしたときだけ通知になる。BEL は既定の bellStyle `audible` で音を鳴らし、
  タブにベルの印を付ける。タスクバーを点滅させるには `taskbar` を足す必要がある
- tmux 3.7c(既定の設定、allow-passthrough off): pty で外側への出力を測ると、
  BEL は出るが OSC 9 と OSC 777 は捨てられた。allow-passthrough on で
  DCS passthrough に包むと、OSC 9 と OSC 777 も外側へ出た
- 実機で裏の tmux ウィンドウから 3 つを出し、Windows の画面を
  スクリーンショットで撮った。トーストもタスクバーの変化も出ず、tmux が
  ウィンドウにベルの印を付けただけだった

端末を通る手段では、見える形で届くものがない。そこで次の 2 つを足した。

- notifyCommand: 止まったときに動かすシェルコマンドを設定で指定する。
  メッセージは MSA_NOTIFY_MESSAGE で渡し、文字列をコマンドに埋めないので
  エラー文がシェルに解釈されない。clipboardImageCommand と同じく agent
  ディレクトリの設定でだけ読む。プロジェクトの設定から任意のコマンドを
  動かせないようにするため。core で動かすので interactive・print・rpc の
  どのモードでも動く。失敗は transcript に残す。知らせが届かなかったことに
  気づけないと、#164 と同じく止まったまま時間を失うため
- tmux の中(TMUX が設定されている)では OSC 9 と OSC 777 を DCS passthrough に
  包み、BEL は包まずに出す。tmux は BEL を自分で外へ渡すので、包むと
  allow-passthrough off のときに BEL まで捨てられる

notifyCommand は実機で確かめた。この枝の msa を tmux の裏ウィンドウで
interactive で起動し、402 を返すローカルの HTTP サーバーへ向けて止めた。
notifyCommand から Windows のタスク(conhost.exe --headless powershell.exe)
でトーストを出すと、Windows の画面に止まった旨のメッセージが出ることを
スクリーンショットで確かめた。

あわせて、402・残高不足・クォータ切れで program status を kind `auth` に
していたのを直した。provider_stalled に providerUnusableReason の理由を載せ、
401・403・鍵の誤りは `auth`、402・残高・クォータは `quota` にする。
Program Status Protocol の kind は permission・question・auth に固定されていて、
新しい kind は端末が support query の返事の `kinds` に挙げたときだけ使う
決まりなので、ProcessTerminal は返事の `kinds` を読み、挙がっていない kind は
付けずに `blocked` だけを送る。

テストで、notifyCommand がメッセージ付きで動くこと、失敗が transcript に
残ること、tmux の中で包むこと、kind が理由どおりになること、返事に無い kind を
落とし、挙がった kind は送ることを固定した。notifyCommand の呼び出し・env の
受け渡し・失敗の記録・passthrough・kind の取り出し・返事の kinds の読み取りを
それぞれ外すとテストが落ちることを確かめた。
masseater added a commit to masseater/msa that referenced this pull request Oct 24, 2026
* fix: 再試行で直らない provider の失敗で、enabledModels の別のモデルへ移り、移れなければ端末に知らせる

- 401・402・403・不正なキー・残高不足・quota 切れは待っても直らないのに、セッションは
  黙って止まっていた。401 の本文は "server_error" を含むので、再試行の対象にも当たって
  いた。libs/ai に isProviderUnusableError を足し、これに当たる失敗は再試行しないように
  した。判定を 1 か所に置き、再試行とフォールバックが同じ基準を使うようにするため
- 当たったら、enabledModels(起動時の選択と Ctrl+P の範囲)の順に、認証があり、まだ
  失敗していない provider のモデルへ移り、失敗した応答を context から外して送り直す。
  切り替え先の設定項目を新しく作らなかったのは、ユーザーが使ってよいと決めたモデルの
  一覧が enabledModels として既にあり、設定を 2 か所に持たないため。enabledModels が
  空なら移らない。勝手に別の provider で課金しないため
- 移れるモデルが無ければ止まり、止まった時刻と原因のエラーを transcript に残す。interactive
  mode は BEL と OSC 9・OSC 777 の通知を出し、端末のタイトルに "(stopped)" を付け、
  program status を blocked にする。ssh 越しの端末でも、タブやタスクバーで気づけるように
  するため。同じ停止の間は 1 回だけ知らせる
- 停止と再開のメッセージの時刻は formatLocalDateTime で書く。画面に出す時刻はマシンの
  タイムゾーンでここだけで作る決まりで、UTC のままだと読むたびに直す手間が要るため
- 止まっている間に届いた報告は transcript に残り、届くたびの呼び出しも失敗するだけで
  追加の通知は出さない。/model か Ctrl+P でモデルを変えると、止まっていた run をその
  報告ごと再開する。モデルを変えたあと誰かが入力するまで報告が放置されないようにするため
- cycleModel・setModel の切り替え処理を switchModel にまとめ、フォールバックも同じ経路を
  通るようにした

テストは本物の AgentSession・ModelRuntime・AuthStorage を一時ディレクトリに作り、
402 を返す provider から次のモデルへ移って送り直すこと、移れないときに 1 回だけ止まって
時刻とエラーを残すこと、止まっている間の報告をモデルの切り替え後に拾うことを確かめた。
interactive mode の通知は SessionEventRouter に停止・復帰・切り替えのイベントを流して
確かめた。停止の時刻を UTC の ISO に戻すと停止のテストが落ちる。各判定を外すと対応するテストが落ちることも確かめた。

Closes #164

* fix: 402 などを HTTP ステータスで判定し、モデルを変えて再開したあとの停止も知らせる

レビューで次の 4 点を指摘されたため直す。

- 402 の判定が `\b402\b` の語一致で、`max_tokens: 402` のように
  エラー文に数字があるだけで「provider が使えない」と判定していた。
  再試行の 429/500/502/503/504/520/524 も同じ語一致で、
  `max_tokens 500` のような 400 を再試行していた。provider の
  エラー文は SDK と formatProviderError がステータスを先頭
  (`402 ...`・`402: ...`)か `Prefix (402):`、`status code 402`、
  JSON の `"code":402` の形で書くので、そこからステータスを読み、
  401/402/403 と再試行するステータスはその値で判定する。
  支払い・認証の種別を表す語(payment required など)はそのまま残す。
  retry.test.ts が行数の上限を超えるので、ステータスの判定の
  テストは retry-status.test.ts に分ける。
- 成功時に failedProviders を空にする処理と、Ctrl+P(cycleModel)
  から再開する経路を固定するテストがなかった。
- 停止の記録(stalledInternal)が成功するまで残るので、モデルを
  変えて再開したあと再び止まっても stall() が何もせず、通知も
  transcript の記録も出なかった。再開した時点で停止の記録を消し、
  provider_recovered に使う停止時刻は別に持つ。

* fix: 再試行と provider 切り替えを、エラー文ではなく HTTP ステータスの数値で判定する

前の修正では、402 を語として拾う誤判定を避けるために、数字だけの
429/500/502/503/504/520/524 をパターンから外し、エラー文の先頭や
`(NNN):` の形からだけステータスを読んでいた。そのため main で再試行
していた `Proxy error: 502 Bad Gateway`・`Proxy error: 524 `・
`error code: 524`・`HTTP 429`・`request failed: 429`・
`Upstream error 503` が再試行されなくなり、`Proxy error: 403 ` も
使えない provider と判定されなかった。

原因は、ステータスが数値として手元にあるのに、文字列に埋めてから
文字列で読み戻していたこと。normalizeProviderError().status と proxy の
response.status を AssistantMessage.errorStatus に数値で持たせ、
isRetryableAssistantError と isProviderUnusableError はまずこの数値で
判定する。数値が文字列と食い違うときは数値を正とする。

- Anthropic・OpenAI Completions・OpenAI Responses・OpenAI Codex・Google
  の失敗で errorStatus を記録する。Codex の SSE は HTTP エラーを本文の
  message だけの Error にしていて status を落としていたので、status を
  載せて投げる
- proxy は HTTP エラーの status を ProxyError に持たせて message に移す。
  本文に error があると文が `Proxy error: <error>` になり数字が消えるため、
  数値で持たないと判定できなかった。proxy の error イベントの
  errorStatus もそのまま移す
- 数値を持たない古い記録と外部から来たエラー文は、文字列から補う。
  先頭か、`HTTP`・`status`・`error`・`error code`・`failed`・`returned`・
  `answered`・`(`・JSON の `code`/`status` の直後にある 3 桁だけを
  ステータスとみなす。リポジトリでステータス入りのエラー文を組み立てて
  いる箇所(formatProviderError、proxy、llama.cpp・classifier の
  `returned`、OAuth・OpenRouter の `failed`、embeddings の `answered`、
  `status=`)はすべてこの形に当たる。`max_tokens: 402` のような数字は
  前置きがないのでステータスとみなさない
- エラー文が空でも errorStatus があれば判定する

テストで、上の文字列すべてと formatProviderError が組み立てる文が
main と同じく判定されること、誤判定の例が false のままであること、
各 provider と proxy が errorStatus を記録することを固定した。数値を
見ない・文字列を補わない・proxy や各 provider が status を落とす、の
各変更で落ちることを確かめた。

* fix: エラー文の 3 桁は、後ろが文の終わり・記号・理由句のときだけステータスとみなす

再レビューで、予備判定 HTTP_STATUS_IN_TEXT が `error: 402 tokens requested exceeds limit`・
`failed: 403 files could not be read`・`Error: 500 tokens is over max_tokens`・
`500 is not a valid value for max_tokens`・`model returned 500 tokens` を
ステータスとみなすと指摘された。前の形は 3 桁の前にある語(先頭・`error`・
`failed`・`returned` など)しか見ておらず、後ろに数を数える語が続く文を
区別できなかった。

ステータスとして書かれた 3 桁は、後ろが文の終わり・`:`・`)`・`"`・
`status code`・HTTP の理由句(Payment Required、Bad Gateway など)のどれかになる。
数を表す 3 桁は後ろに名詞が続く。この違いで判定する。`status=520;` と
JSON の `"code":503,` は、キーがステータスを名指ししているので、別の式で
`,` `;` `}` が続く形も読む。

あわせて、使えない provider の理由を `auth`(401・403・鍵や権限の誤り)と
`quota`(402・残高不足・クォータ切れ)に分けて返す providerUnusableReason を
足した。402 を認証エラーとして画面に出していたのを直すのに使う。

retry.ts が 300 行を超えたので、エラーの分類を provider-failure.ts に移した。
retry は再試行の入口として、分類の関数も引き続き公開する。index と compat の
依存数の上限と、retry から分類を読む libs/durable をそのままにするため。

テストで、指摘の 5 例が使えない provider にも再試行の対象にもならないこと、
既に固定した文字列(`Proxy error: 502 Bad Gateway`・`Proxy error: 524 `・
`error code: 524`・`HTTP 429`・`request failed: 429`・`Upstream error 503`・
`Proxy error: 403 ` ほか)の判定が変わらないこと、402 と残高・クォータの文が
`quota`、401・403 と鍵の文が `auth` になることを固定した。後ろを見る条件を
`(?!\d)` に戻す、402 を `auth` に戻す、残高の文を `auth` に戻すの
どれでもテストが落ちることを確かめた。

* fix: 止まったことを tmux と Windows Terminal の先にも届け、402 を認証エラーと分けて報告する

止まったときの知らせ(BEL・OSC 9・OSC 777)が、実際の使い方で届くかを
確かめた。経路は、Windows 機の Windows Terminal から ssh で Mac に入り、
tmux の中で msa を動かす形である。

- Windows Terminal 1.24.11911.0(stable): ソース(adaptDispatch.cpp の
  DoConEmuAction)は OSC 9 の数値の副コマンド(4・9・12)だけを扱い、
  `9;msa: ...` の本文は捨てる。OSC 777 は microsoft/terminal#20012 で入り、
  Preview 1.26 から、プロファイルの `compatibility.allowOSC777`(既定 false)を
  true にしたときだけ通知になる。BEL は既定の bellStyle `audible` で音を鳴らし、
  タブにベルの印を付ける。タスクバーを点滅させるには `taskbar` を足す必要がある
- tmux 3.7c(既定の設定、allow-passthrough off): pty で外側への出力を測ると、
  BEL は出るが OSC 9 と OSC 777 は捨てられた。allow-passthrough on で
  DCS passthrough に包むと、OSC 9 と OSC 777 も外側へ出た
- 実機で裏の tmux ウィンドウから 3 つを出し、Windows の画面を
  スクリーンショットで撮った。トーストもタスクバーの変化も出ず、tmux が
  ウィンドウにベルの印を付けただけだった

端末を通る手段では、見える形で届くものがない。そこで次の 2 つを足した。

- notifyCommand: 止まったときに動かすシェルコマンドを設定で指定する。
  メッセージは MSA_NOTIFY_MESSAGE で渡し、文字列をコマンドに埋めないので
  エラー文がシェルに解釈されない。clipboardImageCommand と同じく agent
  ディレクトリの設定でだけ読む。プロジェクトの設定から任意のコマンドを
  動かせないようにするため。core で動かすので interactive・print・rpc の
  どのモードでも動く。失敗は transcript に残す。知らせが届かなかったことに
  気づけないと、#164 と同じく止まったまま時間を失うため
- tmux の中(TMUX が設定されている)では OSC 9 と OSC 777 を DCS passthrough に
  包み、BEL は包まずに出す。tmux は BEL を自分で外へ渡すので、包むと
  allow-passthrough off のときに BEL まで捨てられる

notifyCommand は実機で確かめた。この枝の msa を tmux の裏ウィンドウで
interactive で起動し、402 を返すローカルの HTTP サーバーへ向けて止めた。
notifyCommand から Windows のタスク(conhost.exe --headless powershell.exe)
でトーストを出すと、Windows の画面に止まった旨のメッセージが出ることを
スクリーンショットで確かめた。

あわせて、402・残高不足・クォータ切れで program status を kind `auth` に
していたのを直した。provider_stalled に providerUnusableReason の理由を載せ、
401・403・鍵の誤りは `auth`、402・残高・クォータは `quota` にする。
Program Status Protocol の kind は permission・question・auth に固定されていて、
新しい kind は端末が support query の返事の `kinds` に挙げたときだけ使う
決まりなので、ProcessTerminal は返事の `kinds` を読み、挙がっていない kind は
付けずに `blocked` だけを送る。

テストで、notifyCommand がメッセージ付きで動くこと、失敗が transcript に
残ること、tmux の中で包むこと、kind が理由どおりになること、返事に無い kind を
落とし、挙がった kind は送ることを固定した。notifyCommand の呼び出し・env の
受け渡し・失敗の記録・passthrough・kind の取り出し・返事の kinds の読み取りを
それぞれ外すとテストが落ちることを確かめた。

* fix: 認証エラーと残高切れは、HTTP ステータスか provider のエラー種別があるときだけ使えない provider とみなす

`unauthorized` や `permission.?denied` を文中のどこかに含むだけで認証エラーとしていたため、
`EACCES: permission denied, open '/x'` のような provider 以外のエラー文でも provider を切り替え、
移った先での課金や停止の通知を起こしえた。402 の語一致と同じ種類の誤判定である。

使えない provider の判定は、errorStatus(401/402/403)か、エラー文の中の provider のエラー形式に限る。
認証は JSON の `type`・`code`・`status` が authentication_error・permission_error・invalid_api_key・
PERMISSION_DENIED・UNAUTHENTICATED のとき、残高切れは insufficient_quota・billing_error・
payment_required などの provider 固有の識別子や文言のときだけにする。`quota exceeded`・`billing` の
ような一般語は `Disk quota exceeded` などにも当たるので、使えない provider の判定には使わず、
main と同じく再試行しない理由としてだけ残す。

provider 以外のエラー文 8 通りが使えない provider と判定されないこと、本物の 401/403 は判定されることを
テストで固定した。前の語一致に戻すと、その 8 通りがすべて落ちる。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-VT Virtual Terminal sequence support Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. zBugBash-Consider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send Desktop Notification via VT Sequence (OSC777)

8 participants