aiterm-mcp 0.61.20 → 0.61.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/README.ja.md +12 -1
- package/README.md +13 -1
- package/dist/core.js +159 -47
- package/dist/errors.js +1 -0
- package/dist/harnesses/codex.js +16 -6
- package/dist/harnesses/cursor.js +28 -1
- package/dist/harnesses/grok.js +25 -2
- package/dist/index.js +6 -0
- package/docs/DESIGN.md +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.61.22] - 2026-10-28
|
|
11
|
+
|
|
12
|
+
- Resolve Codex model picker labels through the native model catalog when display names differ from model IDs, including names containing spaces. Keep exact row matching and reject ambiguous labels without choosing another model.
|
|
13
|
+
- Resolve Claude catalog aliases and custom IDs through their native display names instead of choosing the first model in a family; require exact Cursor base IDs and their supported effort variants. Preserve Grok's exact native-ID controls.
|
|
14
|
+
- Require a fresh Codex model-change notice matching the requested model and effort. Return typed configuration errors for all four harnesses, distinguishing requests refused before a change from possibly applied or partially applied changes, without retrying them.
|
|
15
|
+
|
|
16
|
+
## [0.61.21] - 2026-10-26
|
|
17
|
+
|
|
18
|
+
- Distinguish tmux PTY EOF from a confirmed authentication process exit: observe missing exit status/signal for a bounded interval, preserve signals and nonzero exits as failures, and reject replaced generations without restarting login.
|
|
19
|
+
- Re-read the current Grok rate-limit panel once after an error event when waiting; preserve ordinary errors, one-shot reads, new turns and closed launches without replaying input.
|
|
20
|
+
- Observe authorization-code redraws for up to three seconds after a single native submission. Preserve unknown outcomes at the deadline or on generation replacement, without resubmitting or claiming authentication success.
|
|
21
|
+
- Recognize a current Cursor `prepaid_balance_exhausted` provider refusal without a new transcript user record as typed error only from a complete current error JSON object. Quoted diagnostic codes, malformed JSON, resumed composers and Codex 429 retries remain nonterminal; do not retry, close, or change credentials.
|
|
22
|
+
|
|
10
23
|
## [0.61.20] - 2026-10-26
|
|
11
24
|
|
|
12
25
|
- Clear an existing UserPaused/Idle Grok goal on the original worker through one user-origin native command, with fresh durable acknowledgement and authoritative no-goal readback. Refuse busy input, drafts and replaced bindings; preserve unknown effects without retry.
|
|
@@ -2900,7 +2913,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
2900
2913
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
2901
2914
|
provenance.
|
|
2902
2915
|
|
|
2903
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.
|
|
2916
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.22...HEAD
|
|
2917
|
+
[0.61.22]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.21...v0.61.22
|
|
2918
|
+
[0.61.21]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.20...v0.61.21
|
|
2904
2919
|
[0.61.20]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.19...v0.61.20
|
|
2905
2920
|
[0.61.19]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.18...v0.61.19
|
|
2906
2921
|
[0.61.18]: https://github.com/kitepon/aiterm-mcp/compare/v0.61.17...v0.61.18
|
package/README.ja.md
CHANGED
|
@@ -209,7 +209,7 @@ runtime-error store は canonical dotagents config の `collection.enabled: true
|
|
|
209
209
|
場合だけ収集し、既定OFF、network送信は行いません。tag起点CIのnpm provenance(OIDC Trusted
|
|
210
210
|
Publishing)で公開し、GitHub Release が Official MCP Registry を再登録します。
|
|
211
211
|
|
|
212
|
-
**状態:** 開発継続中 · 現行公開版 **v0.61.
|
|
212
|
+
**状態:** 開発継続中 · 現行公開版 **v0.61.22** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
213
213
|
|
|
214
214
|
### 更新と巻き戻し
|
|
215
215
|
|
|
@@ -263,6 +263,7 @@ ClaudeがAPIエラーや安全判定の拒否で終了した時は、Stop hook
|
|
|
263
263
|
|
|
264
264
|
Codexがサービスの誤りや通信の失敗でturnを打ち切った時は、完了待ちが`done`ではなく`error`を返す(`aiterm-wait`はexit 7、親への配送は`outcome=error`)。`error`は応答の本文とURLを落とした1行の文で、Codexが記録した種類(`internal_server_error`・`http_connection_failed`など)は`error_kind`に載る。利用上限は今までどおり`rate_limited`。誤りで終わった後の席は、次の`pty_send`を新しいturnとして受ける。
|
|
265
265
|
Cursorが誤りでturnを終えた時(記録の`turn_ended`が`status: "error"`)も同じで、完了待ちは`error`を返し、文の頭の角括弧の名前(`unavailable`など)を`error_kind`に載せる。利用上限の文は`rate_limited`、席で止めたturn(`User aborted request`)は今までどおり`done`。
|
|
266
|
+
現在の`Error:`以降が完全なJSONで、`error.code`が`prepaid_balance_exhausted`なら、新しいuser記録が無くても同じ種類の`error`を返す。説明文中のcode、壊れたJSON、後続の入力欄や実行中表示がある旧エラーでは終端にしない。自動再送や席の閉鎖は行わない。
|
|
266
267
|
|
|
267
268
|
agent配送だけを期待する連携では、`pty_send`に`require_agent:true`を指定する。agent登録が無ければ、打鍵前に`AGENT_SESSION_REQUIRED`と「文字列は送信していません」を返す。省略時は通常PTY送信を維持する。`force:true`との併用は未送信で拒否する。
|
|
268
269
|
|
|
@@ -280,6 +281,8 @@ Grokの無人起動は公式`--trust`で指定された作業フォルダを信
|
|
|
280
281
|
|
|
281
282
|
Grokで終了済みターンのweekly-limitパネルが残っている場合、次の通常`pty_send`が`Shift+X`で一度閉じ、入力受付を確認して今回の本文を送る。同じsessionと会話を保ち、receiptの`pane_input_recovery`に`grok_rate_limit_dialog_dismissed`を記録する。ターン未終了・harness不在は`GROK_RATE_LIMIT_RECOVERY_BLOCKED`、解除後の入力受付失敗は`GROK_RATE_LIMIT_RECOVERY_FAILED`となり、本文は未送信。上限の継続は`rate_limited`として返し、過去promptは再送しない。Grokの上限観測には現在の画面だけを使う。Claude Codeの上限は現在の画面の入力欄の下に出る知らせで、Codexの上限はturnを終えた記録(`task_complete`の`codex_error_info: "usage_limit_exceeded"`)で見分ける。pane logや道具の出力に残る上限の文字では判定しない。
|
|
282
283
|
|
|
284
|
+
Grokの待機中にerror eventが先に現れた場合は、見回り一回分後に現在の上限panelを読み直す。上限が無ければ元のerrorを返し、次turnや消失したlaunchへ古いerrorを結び付けない。timeout=0の即時照会は待たず、入力やAPI要求は再送しない。
|
|
285
|
+
|
|
283
286
|
Cursorの送信前hook(`beforeSubmitPrompt`と、互換読込するClaude Codeの`UserPromptSubmit`)がpromptを拒否すると、Cursorはpromptを捨て、turnも完了も起きない。Aitermはこの拒否の表示を見分け、起動時promptは`initial_prompt=failed`、`pty_send`は成功receiptを返さず、どちらも`USER_HOOK_BLOCKED`とhookの出力を返す。確認時間(3秒)より後の拒否は、完了待ちが`outcome=error`(`aiterm-wait`はexit 7)で返す。
|
|
284
287
|
|
|
285
288
|
Grokがread-only sandboxの適用を拒否した場合、prompt送信時に`GROK_SANDBOX_STARTUP_FAILED`とCLIの原因を返す。例えばhookのパスにシンボリックリンクがあるとGrok CLIは起動を拒否する。設定の管理元で原因を修正し、対象sessionを`pty_close`して起動し直す。Aitermはsandboxを解除したりhookをコピーしたりしない。
|
|
@@ -628,6 +631,10 @@ Aitermは、既定では実行時エラーをどこへも送らない。送る
|
|
|
628
631
|
|
|
629
632
|
`agent_configure({ session_id, model?, reasoning_effort?, fast? })`はharness標準操作で起動中のClaude/Codex/Grok/Cursorを変更し、PTYと会話contextを維持する。
|
|
630
633
|
|
|
634
|
+
model IDは各harnessの正規catalogを使う。ClaudeのaliasとCodexのIDと異なるpicker名はcatalogの表示名へ結び、Cursorは完成ID又はそのIDに対応するeffortの組だけを認める。固定のモデル許可表や別modelへの置換は加えない。Codexの成功には指定ID・effortに一致する新しいnative変更通知が必要。
|
|
635
|
+
|
|
636
|
+
全4harnessの設定変更失敗は、`isError: true`と元エラー文を保ち、`structuredContent: { schema: "aiterm.agent-configure-error.v1", session_id, outcome, effect }`を返す。`not_applied`/`not_started`は当該要求のmodel・effort・fast変更を発行し得る前の拒否。`outcome_unknown`/`possible`は変更を発行した可能性があり、一部変更後の別項目失敗も含むので自動再送しない。以前の実設定の証明や別要求の不確定解除には使わない。この型付き結果を持たない旧serverの失敗は未確認として扱う。成功の`aiterm.agent-configure-result.v1`は維持する。
|
|
637
|
+
|
|
631
638
|
**ファスト(`fast`)。** 各harnessの、費用や利用量を多く払って応答を速くする切り替え(Claude Codeの`/fast`、Codexの速度の段、GrokとCursorのfast版のmodel)を、席ごとに切り替える(ADR 0114)。
|
|
632
639
|
|
|
633
640
|
- 席は必ず通常の速度で起きる。`agent_launch`の`fast`を省いた時とfalseは同じで、利用者の設定にファストが残っていても通常で始まる。`fast: true`は通常で起こしてから、その席を切り替える。
|
|
@@ -640,6 +647,10 @@ Aitermは、既定では実行時エラーをどこへも送らない。送る
|
|
|
640
647
|
|
|
641
648
|
認証UIは追加の`auth_ui`を使う。`stage`は`open_url` / `device_code` / `paste_code` / `select` / `waiting` / `complete` / `failed` / `unavailable`。公式URL・表示code・具体的な選択ラベル・入力種別をNativeが返し、`input_required`だけから入力内容や端末キーを推測しない。`respond`は直近の`auth_ui.binding`を`expected_binding`へ渡し、`expected_prompt_digest`には同じ`auth_ui.prompt_digest`を渡す。`response:{kind:"authorization_code",value}`または`{kind:"choice",id}`を同じ認証flowへ送る。認証コードを`pty_send`へ渡さない。専用入力はlastcmd・通常turn・paneログ・argv・一時fileへコードを保存せず、CLIの画面echoもpaneログへ保存しない。未発行と入力後不明は構造化errorの`effect:not_issued|unknown`で区別し、自動再送しない。legacy flowの`launch_id:null`は実native識別情報で照合し、UUIDを補わない。Windowsの専用入力は前面所有確認が未受入のため`not_issued`で拒否する。
|
|
642
649
|
|
|
650
|
+
コード入力後は同じ認証世代の状態を最大3秒確認する。画面更新後のwaitingは処理待ちで、認証成功を意味しない。入力待ちが変わらない・世代が変わる・状態を読めない場合はunknownを保ち、入力を再送しない。
|
|
651
|
+
|
|
652
|
+
認証processの端末切断が終了コード確定に先行した時は、同じ世代の終了コード・signalを3秒の期限付きで確認する。signal終了や非0は失敗を保ち、0でも公式statusを確認する。期限まで不明、session消失・交代は成功にせず、ログインの再起動や入力再送は行わない。
|
|
653
|
+
|
|
643
654
|
|
|
644
655
|
`start`は、公式の状態が認証済みなら何も起こさず`authenticated`(`session_id:null`)を返す。`relogin:true`を付けると、認証済みに見えても公式ログインを開始し、`session_id`付きの結果を返す。別のアカウントへ入り直す時と、ログインの期限切れを状態から見抜けない時に使う。Aitermは資格情報を消さず、置き換えは公式CLIが行う。ただし、公式CLIがログインを始めた時点で元のログインを消す事がある(Codex 0.160.0の`codex login --device-auth`は、始めた時点で`auth.json`を消す。途中で`cancel`しても戻らない)。Claude CodeとCursorは、途中で`cancel`すれば元の資格情報が残る(無効な資格情報で確認)。
|
|
645
656
|
|
package/README.md
CHANGED
|
@@ -227,7 +227,7 @@ collection is off by default and performs no network I/O. It ships via
|
|
|
227
227
|
tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
|
|
228
228
|
Release re-registers the Official MCP Registry entry.
|
|
229
229
|
|
|
230
|
-
**Status:** actively maintained · current public release **v0.61.
|
|
230
|
+
**Status:** actively maintained · current public release **v0.61.22** · runs on Linux · WSL2 · macOS · native Windows (tmux on POSIX, the tmux-CLI-compatible [psmux](https://github.com/psmux/psmux) on native Windows — no WSL required) · MIT · see the [CHANGELOG](CHANGELOG.md).
|
|
231
231
|
|
|
232
232
|
### Update and rollback
|
|
233
233
|
|
|
@@ -305,8 +305,12 @@ Grokの無人起動は公式`--trust`で指定された作業フォルダを信
|
|
|
305
305
|
|
|
306
306
|
Grokで終了済みターンのweekly-limitパネルが残っている場合、次の通常`pty_send`が`Shift+X`で一度閉じ、入力受付を確認して今回の本文を送る。同じsessionと会話を保ち、receiptの`pane_input_recovery`に`grok_rate_limit_dialog_dismissed`を記録する。ターン未終了・harness不在は`GROK_RATE_LIMIT_RECOVERY_BLOCKED`、解除後の入力受付失敗は`GROK_RATE_LIMIT_RECOVERY_FAILED`となり、本文は未送信。上限の継続は`rate_limited`として返し、過去promptは再送しない。Grokの上限観測には現在の画面だけを使う。Claude Codeの上限は現在の画面の入力欄の下に出る知らせで、Codexの上限はturnを終えた記録(`task_complete`の`codex_error_info: "usage_limit_exceeded"`)で見分ける。pane logや道具の出力に残る上限の文字では判定しない。
|
|
307
307
|
|
|
308
|
+
Grokの待機中にerror eventが先に現れた場合は、見回り一回分後に現在の上限panelを読み直す。上限が無ければ元のerrorを返し、次turnや消失したlaunchへ古いerrorを結び付けない。timeout=0の即時照会は待たず、入力やAPI要求は再送しない。
|
|
309
|
+
|
|
308
310
|
When a Cursor pre-submit hook (`beforeSubmitPrompt`, or a Claude Code `UserPromptSubmit` hook that Cursor loads for compatibility) rejects the prompt, Cursor drops it and no turn or completion follows. Aiterm recognizes the rejection: an initial prompt returns `initial_prompt=failed`, and `pty_send` returns an error instead of a success receipt, both with `USER_HOOK_BLOCKED` and the hook's output. A rejection that comes after the 3-second start check is reported by the completion wait as `outcome=error` (`aiterm-wait` exit 7).
|
|
309
311
|
|
|
312
|
+
A current Cursor `Error:` containing a complete JSON object with `error.code` equal to `prepaid_balance_exhausted` ends the wait as `outcome=error` with that `error_kind`, even without a new user record. Quoted diagnostic codes, malformed JSON and old errors followed by a composer or busy display do not establish this terminal. Aiterm does not resend or close the session.
|
|
313
|
+
|
|
310
314
|
Grokがread-only sandboxの適用を拒否した場合、prompt送信時に`GROK_SANDBOX_STARTUP_FAILED`とCLIの原因を返す。hookパスのシンボリックリンクなど、CLIが示した原因を設定の管理元で修正し、対象sessionを`pty_close`して起動し直す。Aitermはsandboxを解除したりhookをコピーしたりしない。
|
|
311
315
|
|
|
312
316
|
この判定はGrok専用アダプターが所有する。初回prompt付きの`agent_launch`と通常の`pty_send`で、入力受付待ち中に拒否を検出すると未送信のエラーを返す。promptなし・`trust_project`指定なしの起動応答は入力受付を保証しない。`trust_project:true`では入力受付まで確認し、`startup.status`を返す。Grokのprivacy notice起動設定も同アダプターが所有する。実装の責務分担は[DESIGN](docs/DESIGN.md#failure-and-recovery)を参照。
|
|
@@ -670,6 +674,10 @@ enables collection on that host.
|
|
|
670
674
|
|
|
671
675
|
`agent_configure({ session_id, model?, reasoning_effort?, fast? })` changes a running Claude, Codex, Grok, or Cursor TUI through the harness's standard controls, preserving the PTY and conversation context.
|
|
672
676
|
|
|
677
|
+
Model IDs come from each harness's native catalog. Claude aliases and differing Codex picker labels use that catalog's display name; Cursor matches complete native IDs or their exact supported effort variants. No model allowlist or alternate-model fallback is added. Codex success requires a fresh native change notice matching the requested ID and effort.
|
|
678
|
+
|
|
679
|
+
Configuration failures keep `isError: true` and the original error text, with `structuredContent: { schema: "aiterm.agent-configure-error.v1", session_id, outcome, effect }` for all four harnesses. `not_applied` / `not_started` means this request failed before a model, effort, or fast change could be issued. `outcome_unknown` / `possible` means a change may have been issued, including partial application before a later failure; do not replay it automatically. This receipt does not certify the session's previous configuration or clear unrelated uncertainty. Older servers without this receipt must be treated as unconfirmed on failure. Successful results retain `aiterm.agent-configure-result.v1`.
|
|
680
|
+
|
|
673
681
|
**ファスト(`fast`)。** 各harnessの、費用や利用量を多く払って応答を速くする切り替え(Claude Codeの`/fast`、Codexの速度の段、GrokとCursorのfast版のmodel)を、席ごとに切り替える(ADR 0114)。
|
|
674
682
|
|
|
675
683
|
- 席は必ず通常の速度で起きる。`agent_launch`の`fast`を省いた時とfalseは同じで、利用者の設定にファストが残っていても通常で始まる。`fast: true`は通常で起こしてから、その席を切り替える。
|
|
@@ -684,6 +692,10 @@ Claude Codeの席では、`/model`の選ぶ画面の`s`(use this session only
|
|
|
684
692
|
|
|
685
693
|
認証UIは追加の`auth_ui`を使う。`stage`は`open_url` / `device_code` / `paste_code` / `select` / `waiting` / `complete` / `failed` / `unavailable`。公式URL・表示code・具体的な選択ラベル・入力種別をNativeが返し、`input_required`だけから入力内容や端末キーを推測しない。`respond`は直近の`auth_ui.binding`を`expected_binding`へ渡し、`expected_prompt_digest`には同じ`auth_ui.prompt_digest`を渡す。`response:{kind:"authorization_code",value}`または`{kind:"choice",id}`を同じ認証flowへ送る。認証コードを`pty_send`へ渡さない。専用入力はlastcmd・通常turn・paneログ・argv・一時fileへコードを保存せず、CLIの画面echoもpaneログへ保存しない。未発行と入力後不明は構造化errorの`effect:not_issued|unknown`で区別し、自動再送しない。legacy flowの`launch_id:null`は実native識別情報で照合し、UUIDを補わない。Windowsの専用入力は前面所有確認が未受入のため`not_issued`で拒否する。
|
|
686
694
|
|
|
695
|
+
コード入力後は同じ認証世代の状態を最大3秒確認する。画面更新後のwaitingは処理待ちで、認証成功を意味しない。入力待ちが変わらない・世代が変わる・状態を読めない場合はunknownを保ち、入力を再送しない。
|
|
696
|
+
|
|
697
|
+
認証processの端末切断が終了コード確定に先行した時は、同じ世代の終了コード・signalを3秒の期限付きで確認する。signal終了や非0は失敗を保ち、0でも公式statusを確認する。期限まで不明、session消失・交代は成功にせず、ログインの再起動や入力再送は行わない。
|
|
698
|
+
|
|
687
699
|
|
|
688
700
|
`start`は、公式の状態が認証済みなら何も起こさず`authenticated`(`session_id:null`)を返す。`relogin:true`を付けると、認証済みに見えても公式ログインを開始し、`session_id`付きの結果を返す。別のアカウントへ入り直す時と、ログインの期限切れを状態から見抜けない時に使う。Aitermは資格情報を消さず、置き換えは公式CLIが行う。ただし、公式CLIがログインを始めた時点で元のログインを消す事がある(Codex 0.160.0の`codex login --device-auth`は、始めた時点で`auth.json`を消す。途中で`cancel`しても戻らない)。Claude CodeとCursorは、途中で`cancel`すれば元の資格情報が残る(無効な資格情報で確認)。
|
|
689
701
|
|
package/dist/core.js
CHANGED
|
@@ -43,7 +43,7 @@ import { FastModeError, fastModeFailure } from "./fast-mode.js";
|
|
|
43
43
|
import { readFileOrNull, restoreJsonSetting, withUserConfigLock } from "./user-config.js";
|
|
44
44
|
import { isDeepStrictEqual } from "node:util";
|
|
45
45
|
import { grokAuthPlan, grokAuthStatus, grokAuthPane, GROK_MODEL_DEFAULTS, realGrokHome, resolveAndValidateGrokAuth, assertGrokModelAvailable, grokModelChoices, grokModelFromFooter, grokFooterModelName, grokModelDefaultsFromBody, restoreGrokModelDefaults, grokEventsTranscript, grokSessionDirectory, latestGrokCompletion, grokTurnSettled, observeGrokDone, buildGrokAgentCmd, grokAgentArgv, grokLaunchNote, grokEnvTokens, grokEnvEntries, grokTuiReady, grokPaneObservation, GROK_INTERRUPT_KEY, grokRateLimitDialog, grokPromptAwaitingAccept, grokUnacceptedPromptRestored, grokStartupAction, grokFooterHasConfiguration, grokTranscriptText, createGrokAgentMetadata, } from "./harnesses/grok.js";
|
|
46
|
-
import { codexAuthPlan, codexAuthStatus, codexAuthPane, realCodexHome, readCodexConfigPins, bindCodexTranscriptSession, latestCodexCompletion, codexTurnSettled, codexRunningTurn, codexInterruptionRecord, observeCodexDone, buildCodexAgentCmd, codexAgentArgv, codexLaunchNote, codexPaneObservation, CODEX_INTERRUPT_KEY, codexHelperProcess, codexRateLimitModelSwitchDialog, codexApprovalDialog, codexStartupAction, codexModelChoice, codexEffortChoice, codexMoreReasoningChoice, codexTranscriptText, createCodexAgentMetadata, codexModelChoices, codexFastCommandOffered, codexFooterShowsFast, codexServiceTierNotices, restoreCodexDefaults, restoreCodexDefaultInFile, } from "./harnesses/codex.js";
|
|
46
|
+
import { codexAuthPlan, codexAuthStatus, codexAuthPane, realCodexHome, readCodexConfigPins, bindCodexTranscriptSession, latestCodexCompletion, codexTurnSettled, codexRunningTurn, codexInterruptionRecord, observeCodexDone, buildCodexAgentCmd, codexAgentArgv, codexLaunchNote, codexPaneObservation, CODEX_INTERRUPT_KEY, codexHelperProcess, codexRateLimitModelSwitchDialog, codexApprovalDialog, codexStartupAction, codexModelChoice, codexModelChangeNotices, codexEffortChoice, codexMoreReasoningChoice, codexTranscriptText, createCodexAgentMetadata, codexModelChoices, codexFastCommandOffered, codexFooterShowsFast, codexServiceTierNotices, restoreCodexDefaults, restoreCodexDefaultInFile, } from "./harnesses/codex.js";
|
|
47
47
|
import { claudeAuthPlan, claudeAuthStatus, claudeAuthPane, OPERATION_ID_RE, CLAUDE_RESULT_MAX_BYTES, CLAUDE_EFFORTS, agentManagedClaudeSettingsPath, agentClaudeResultPath, agentClaudeOperationPath, agentClaudeApprovalReceiptPath, agentClaudeDispatchReceiptPath, validateOperationId, readClaudeResultText, assertClaudeAuthenticationReady, claudeModelChoices, claudeConfigDir, claudeFastIndicatorShown, claudeFastResult, buildClaudeAgentCmd, claudeAgentArgv, claudeLaunchNote, claudePaneObservation, CLAUDE_INTERRUPT_KEY, claudeUsageLimit, claudeLiveSelectMenu, claudeModelPicker, claudeModelPickerRow, claudeModelSwitchConfirm, claudeModelSwitchResult, claudeStartupAction, createClaudeAgentMetadata, claudeSessionTranscriptPath, claudeApiErrorFromLine, claudeApiErrorAfter, } from "./harnesses/claude.js";
|
|
48
48
|
import { cursorAuthPlan, cursorAuthStatus, cursorAuthPane, bindCursorTranscriptSession, cursorTurnBoundary, latestCursorCompletion, observeCursorDone, cursorTranscriptText, assertCursorAuthenticationReady, assertCursorModelAvailable, cursorModelChoices, cursorModelIsFastVariant, cursorFastParameter, cursorHeaderShowsFast, cursorPickerView, cursorEffortSelected, cursorParameterRows, cursorUserConfigPath, CURSOR_DEFAULT_MODEL_KEYS, realCursorHome, buildCursorAgentCmd, cursorAgentArgv, cursorPromptWithLineage, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
49
49
|
import { interimFromNow, readInterimWords, recordInterimBoundary } from "./interim-words.js";
|
|
@@ -4512,12 +4512,28 @@ async function respondAgentAuth(kind, options) {
|
|
|
4512
4512
|
finally {
|
|
4513
4513
|
release();
|
|
4514
4514
|
}
|
|
4515
|
-
await sleep(100);
|
|
4516
4515
|
try {
|
|
4517
|
-
const
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4516
|
+
const initialMeta = loadAuthMetadata(name, kind);
|
|
4517
|
+
const checkReadbackGeneration = (result) => {
|
|
4518
|
+
const current = loadAuthMetadata(name, kind);
|
|
4519
|
+
const stat = fs.lstatSync(authMetadataPath(name));
|
|
4520
|
+
const sameOnboardingLaunch = expected.data.launch_id !== null && initialMeta?.phase === "login" && current?.phase === "onboarding"
|
|
4521
|
+
&& result?.status === "waiting" && result.auth_ui?.binding?.launch_id === expected.data.launch_id;
|
|
4522
|
+
if (!current || (current.launch_id ?? null) !== expected.data.launch_id
|
|
4523
|
+
|| !sameOnboardingLaunch && !expected.data.metadata_identity.startsWith(`${stat.dev}:${stat.ino}:${stat.birthtimeMs}:`))
|
|
4524
|
+
throw new Error("native authentication generation changed");
|
|
4525
|
+
};
|
|
4526
|
+
const deadline = performance.now() + 3000;
|
|
4527
|
+
do {
|
|
4528
|
+
await sleep(100);
|
|
4529
|
+
checkReadbackGeneration();
|
|
4530
|
+
const result = await authenticateAgent(kind, { action: "status", session_id: name });
|
|
4531
|
+
checkReadbackGeneration(result);
|
|
4532
|
+
if (result.auth_ui?.input !== "authorization_code" || response.data.kind !== "authorization_code")
|
|
4533
|
+
return result;
|
|
4534
|
+
// Native input and its redraw are asynchronous; observe without submitting again.
|
|
4535
|
+
} while (performance.now() < deadline);
|
|
4536
|
+
throw new Error("native input consumption unconfirmed");
|
|
4521
4537
|
}
|
|
4522
4538
|
catch {
|
|
4523
4539
|
throw new AuthResponseError("AGENT_AUTH_RESPONSE_UNKNOWN", "unknown", "入力後の状態を確認できません。自動再送しないでください。");
|
|
@@ -4620,19 +4636,52 @@ export async function authenticateAgent(kind, options) {
|
|
|
4620
4636
|
meta = loaded;
|
|
4621
4637
|
}
|
|
4622
4638
|
const session = name;
|
|
4623
|
-
const
|
|
4639
|
+
const exitDeadline = performance.now() + 3000;
|
|
4640
|
+
const deadline = options.action === "start" ? exitDeadline : performance.now();
|
|
4641
|
+
const originalStat = fs.lstatSync(authMetadataPath(session));
|
|
4642
|
+
let pendingExit = false;
|
|
4643
|
+
const pendingExitRefusal = () => {
|
|
4644
|
+
if (!pendingExit)
|
|
4645
|
+
return null;
|
|
4646
|
+
if (!authSessionExists(session))
|
|
4647
|
+
return result("failed", null, "認証sessionが失われました。元の終了状態は未確認です。");
|
|
4648
|
+
const current = loadAuthMetadata(session, kind);
|
|
4649
|
+
const stat = current && fs.lstatSync(authMetadataPath(session));
|
|
4650
|
+
return !current || !stat || (current.launch_id ?? null) !== (meta.launch_id ?? null)
|
|
4651
|
+
|| stat.dev !== originalStat.dev || stat.ino !== originalStat.ino || stat.birthtimeMs !== originalStat.birthtimeMs
|
|
4652
|
+
? result("failed", null, "認証sessionの世代が変わりました。元の終了状態は未確認です。") : null;
|
|
4653
|
+
};
|
|
4624
4654
|
for (;;) {
|
|
4625
4655
|
if (!authSessionExists(session))
|
|
4626
4656
|
return result("failed", null, "認証sessionが失われました。agent_authのstartで開始してください。");
|
|
4627
|
-
const
|
|
4657
|
+
const beforeExitRead = pendingExitRefusal();
|
|
4658
|
+
if (beforeExitRead)
|
|
4659
|
+
return beforeExitRead;
|
|
4660
|
+
const observed = tmux("display-message", "-p", "-t", session, "#{pane_dead}\t#{pane_dead_status}\t#{pane_dead_signal}");
|
|
4628
4661
|
if (observed.code !== 0)
|
|
4629
4662
|
return result("failed", session, "認証processの終了状態を取得できません。");
|
|
4630
|
-
const [dead, exit] = observed.stdout.trim().split("\t");
|
|
4663
|
+
const [dead, exit, signal] = observed.stdout.trim().split("\t");
|
|
4631
4664
|
const pane = authPane(meta, stripControl(captureScreen(session, 0)));
|
|
4665
|
+
const afterExitRead = pendingExitRefusal();
|
|
4666
|
+
if (afterExitRead)
|
|
4667
|
+
return afterExitRead;
|
|
4668
|
+
if (pendingExit && dead === "0")
|
|
4669
|
+
return result("failed", null, "認証processが終了観測中に交代しました。元の終了状態は未確認です。");
|
|
4632
4670
|
if (dead === "1") {
|
|
4671
|
+
// tmux can close the PTY before waitpid publishes either status or signal.
|
|
4672
|
+
if (!exit && !signal && performance.now() < exitDeadline) {
|
|
4673
|
+
pendingExit = true;
|
|
4674
|
+
await sleep(100);
|
|
4675
|
+
continue;
|
|
4676
|
+
}
|
|
4677
|
+
if (signal)
|
|
4678
|
+
return result("failed", session, `公式認証processがsignalで終了しました(signal=${/^[A-Z0-9]+$/.test(signal) ? signal : "unknown"})。`);
|
|
4633
4679
|
if (exit !== "0")
|
|
4634
4680
|
return result("failed", session, `公式認証processが失敗しました(exit=${/^\d+$/.test(exit ?? "") ? exit : "unknown"})。`);
|
|
4635
4681
|
const checked = await authStatus(kind, meta.bin, meta.cwd, authSessionEnvironment(session, meta.env_vars));
|
|
4682
|
+
const afterOfficialStatus = pendingExitRefusal();
|
|
4683
|
+
if (afterOfficialStatus)
|
|
4684
|
+
return afterOfficialStatus;
|
|
4636
4685
|
if (checked.status === "failed")
|
|
4637
4686
|
return result("failed", session, checked.message);
|
|
4638
4687
|
if (checked.status === "unauthenticated")
|
|
@@ -4696,7 +4745,8 @@ const CLAUDE_EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
|
|
|
4696
4745
|
* (2.1.296で確かめた)。引数なしの `/model` の選ぶ画面で s を押すと保存されないので、画面を1歩ずつ読んでそちらを打つ。
|
|
4697
4746
|
* 保存しない選び方が画面に無い時、行やeffortを選べない時は、Escで閉じて何も変えずに断る。
|
|
4698
4747
|
*/
|
|
4699
|
-
async function configureClaudeForSessionOnly(name, meta, model, effort) {
|
|
4748
|
+
async function configureClaudeForSessionOnly(name, meta, model, effort, beforeChange) {
|
|
4749
|
+
let selectionIssued = false;
|
|
4700
4750
|
const screen = () => captureScreen(name, AGENT_TUI_READY_LINES);
|
|
4701
4751
|
const until = async (read, timeoutMs) => {
|
|
4702
4752
|
const deadline = performance.now() + timeoutMs;
|
|
@@ -4717,7 +4767,8 @@ async function configureClaudeForSessionOnly(name, meta, model, effort) {
|
|
|
4717
4767
|
sendMenuChoice(name, "Escape");
|
|
4718
4768
|
await sleep(300);
|
|
4719
4769
|
}
|
|
4720
|
-
throw new AitermError(`${code} vendor=claude session=${name}\n${reason}
|
|
4770
|
+
throw new AitermError(`${code} vendor=claude session=${name}\n${reason}。` +
|
|
4771
|
+
(selectionIssued ? "設定が変わった可能性があります。再送しないでください。" : "modelとreasoning_effortは変えていません。"), 2);
|
|
4721
4772
|
};
|
|
4722
4773
|
const picker = () => claudeModelPicker(screen());
|
|
4723
4774
|
const cursorOf = (p) => p?.rows.find((row) => row.cursor) ?? null;
|
|
@@ -4771,7 +4822,24 @@ async function configureClaudeForSessionOnly(name, meta, model, effort) {
|
|
|
4771
4822
|
break;
|
|
4772
4823
|
seen.add(at);
|
|
4773
4824
|
}
|
|
4774
|
-
|
|
4825
|
+
let target = claudeModelPickerRow([...known.values()], model);
|
|
4826
|
+
if (!target || /^[a-z]+$/iu.test(model)) {
|
|
4827
|
+
const bin = meta.agent_executable ?? resolveAgentBin("claude");
|
|
4828
|
+
if (!bin)
|
|
4829
|
+
return refuse("CLAUDE_MODEL_NOT_IN_PICKER", "Claude CodeのCLIが見つかりません");
|
|
4830
|
+
let catalog;
|
|
4831
|
+
try {
|
|
4832
|
+
catalog = await claudeModelChoices(bin, meta.cwd ?? process.cwd());
|
|
4833
|
+
}
|
|
4834
|
+
catch (error) {
|
|
4835
|
+
return refuse("CLAUDE_MODEL_CATALOG_UNAVAILABLE", error instanceof Error ? error.message : String(error));
|
|
4836
|
+
}
|
|
4837
|
+
const native = catalog.models.find(item => item.id.toLowerCase() === model.toLowerCase());
|
|
4838
|
+
// The native alias can resolve to an older model; picker order is not alias authority.
|
|
4839
|
+
const label = native?.display_name ?? native?.id ?? model;
|
|
4840
|
+
const matching = [...known.values()].filter(row => row.label.toLowerCase() === label.toLowerCase());
|
|
4841
|
+
target = matching.length === 1 ? matching[0] : null;
|
|
4842
|
+
}
|
|
4775
4843
|
if (!target) {
|
|
4776
4844
|
const names = [...known.values()].sort((a, b) => a.index - b.index).map((row) => row.label).join(", ");
|
|
4777
4845
|
return refuse("CLAUDE_MODEL_NOT_IN_PICKER", `Claude Codeの /model の選ぶ画面に ${model} がありません(選べる機種: ${names})`);
|
|
@@ -4817,6 +4885,8 @@ async function configureClaudeForSessionOnly(name, meta, model, effort) {
|
|
|
4817
4885
|
|| (effort && last.effort !== effort)) {
|
|
4818
4886
|
return refuse("CLAUDE_MODEL_PICKER_UNREADABLE", "選ぶ直前の画面が、選んだ行・effortと合いません");
|
|
4819
4887
|
}
|
|
4888
|
+
beforeChange();
|
|
4889
|
+
selectionIssued = true;
|
|
4820
4890
|
sendMenuChoice(name, "s");
|
|
4821
4891
|
let confirmed = false;
|
|
4822
4892
|
const result = await until(() => {
|
|
@@ -5592,33 +5662,43 @@ export async function pauseAgentGoalForStop(target) {
|
|
|
5592
5662
|
return { status: result.availability === "unsupported" || result.outcome === "unsupported" ? "unsupported" : result.outcome === "outcome_unknown" ? "outcome_unknown" : "unavailable", reason: result.reason };
|
|
5593
5663
|
}
|
|
5594
5664
|
export async function configureAgent(name, opts) {
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5665
|
+
let mayHaveChanged = false;
|
|
5666
|
+
const beforeChange = () => { mayHaveChanged = true; };
|
|
5667
|
+
try {
|
|
5668
|
+
assertExecutionContext(name);
|
|
5669
|
+
assertSessionName(name);
|
|
5670
|
+
const model = opts.model?.trim() || null;
|
|
5671
|
+
const effort = opts.reasoning_effort?.trim() || null;
|
|
5672
|
+
const fast = opts.fast ?? null;
|
|
5673
|
+
if (!model && !effort && fast === null)
|
|
5674
|
+
throw new AitermError("model、reasoning_effort、fast のいずれかを指定してください", 2);
|
|
5675
|
+
if ((model && /[\r\n]/.test(model)) || (effort && /[\r\n]/.test(effort))) {
|
|
5676
|
+
throw new AitermError("model/reasoning_effort に改行を含められません", 2);
|
|
5677
|
+
}
|
|
5678
|
+
if (fast === false && modelIsFastVariant(loadAgentMetadata(name).kind, model)) {
|
|
5679
|
+
throw new FastModeError("FAST_MODE_MODEL_CONFLICT", `model=${model} はfast版のIDですが、fast: false が渡されました。元のmodel IDを渡すか、fastを省いてください。設定は変えていません。`);
|
|
5680
|
+
}
|
|
5681
|
+
// 設定替えは席の入力欄へ命令を打つので、送信と同じ行列(ADR 0088)に並ぶ。替えている間に届いた文は、替え終えてから席へ入る(ADR 0120)。
|
|
5682
|
+
// 番が動いている席では、行列を持ったまま番の終わりを待たない(待つ間も、その席への差し込みを通す)。
|
|
5683
|
+
const deadline = performance.now() + AGENT_TUI_READY_TIMEOUT_MS;
|
|
5684
|
+
for (;;) {
|
|
5685
|
+
const result = await withAgentSendLock(name, () => configureAgentInLock(name, model, effort, fast, beforeChange), AGENT_CONFIGURE_UNCHANGED);
|
|
5686
|
+
if (result)
|
|
5687
|
+
return result;
|
|
5688
|
+
if (performance.now() >= deadline)
|
|
5689
|
+
throw new AitermError(`agent session '${name}' は入力待ちではありません`, 2);
|
|
5690
|
+
await sleep(AGENT_TUI_READY_POLL_MS);
|
|
5691
|
+
}
|
|
5692
|
+
}
|
|
5693
|
+
catch (error) {
|
|
5694
|
+
const failure = error instanceof Error ? error : new AitermError(String(error), 2);
|
|
5695
|
+
Object.assign(failure, { configurationFailure: { schema: "aiterm.agent-configure-error.v1", session_id: name,
|
|
5696
|
+
outcome: mayHaveChanged ? "outcome_unknown" : "not_applied", effect: mayHaveChanged ? "possible" : "not_started" } });
|
|
5697
|
+
throw failure;
|
|
5618
5698
|
}
|
|
5619
5699
|
}
|
|
5620
5700
|
/** 返りの null は、席の画面が番の最中を示していて、何も打っていない時。 */
|
|
5621
|
-
async function configureAgentInLock(name, model, effort, fast) {
|
|
5701
|
+
async function configureAgentInLock(name, model, effort, fast, beforeChange) {
|
|
5622
5702
|
// 席の控えは、行列の順番が来てから読む(前の送信が書いた分を、古い控えで上書きしない)。
|
|
5623
5703
|
const meta = loadAgentMetadata(name);
|
|
5624
5704
|
bindCompletedInitialPrompt(meta);
|
|
@@ -5687,16 +5767,19 @@ async function configureAgentInLock(name, model, effort, fast) {
|
|
|
5687
5767
|
throw new AitermError("Claude Code の reasoning_effort は low/medium/high/xhigh/max/ultracode のいずれかです。設定は変えていません。", 2);
|
|
5688
5768
|
}
|
|
5689
5769
|
if (model || level)
|
|
5690
|
-
await configureClaudeForSessionOnly(name, meta, model, level);
|
|
5770
|
+
await configureClaudeForSessionOnly(name, meta, model, level, beforeChange);
|
|
5691
5771
|
if (effort && !level) {
|
|
5772
|
+
beforeChange();
|
|
5692
5773
|
await sendAgentPromptText(name, `/effort ${effort}`);
|
|
5693
5774
|
const effortReady = await waitAgentTuiReady(name, meta, AGENT_TUI_READY_TIMEOUT_MS);
|
|
5694
5775
|
if (!effortReady.ready)
|
|
5695
5776
|
throw new AitermError(`Claudeのeffort変更完了を確認できません`, 2);
|
|
5696
5777
|
}
|
|
5697
5778
|
rememberModel();
|
|
5698
|
-
if (fast !== null)
|
|
5779
|
+
if (fast !== null) {
|
|
5780
|
+
beforeChange();
|
|
5699
5781
|
recordAgentFast(meta, await switchClaudeFast(name, meta, fast, fastVerified));
|
|
5782
|
+
}
|
|
5700
5783
|
else
|
|
5701
5784
|
await dropFastIfUnsupported();
|
|
5702
5785
|
return configured();
|
|
@@ -5724,6 +5807,7 @@ async function configureAgentInLock(name, model, effort, fast) {
|
|
|
5724
5807
|
// Cursorは選んだmodelとパラメータを、利用者の既定(cli-config.json)へも書く版がある。席だけの替えにするため、直前の値へ戻す。
|
|
5725
5808
|
if (model)
|
|
5726
5809
|
await keepingCursorDefaults(meta, async () => {
|
|
5810
|
+
beforeChange();
|
|
5727
5811
|
await sendAgentPromptText(name, `/model ${model}`, meta.kind);
|
|
5728
5812
|
const modelReady = await waitAgentTuiReady(name, meta, AGENT_TUI_READY_TIMEOUT_MS);
|
|
5729
5813
|
if (!modelReady.ready)
|
|
@@ -5759,8 +5843,10 @@ async function configureAgentInLock(name, model, effort, fast) {
|
|
|
5759
5843
|
throw new AitermError("Cursorのreasoning effort変更完了を確認できません", 2);
|
|
5760
5844
|
});
|
|
5761
5845
|
rememberModel();
|
|
5762
|
-
if (fast !== null)
|
|
5846
|
+
if (fast !== null) {
|
|
5847
|
+
beforeChange();
|
|
5763
5848
|
recordAgentFast(meta, await switchCursorFast(name, meta, fast));
|
|
5849
|
+
}
|
|
5764
5850
|
else if (model) {
|
|
5765
5851
|
// modelを替えた後の実際の状態を、見出しのmodelの表示で読む。
|
|
5766
5852
|
const shown = cursorHeaderShowsFast(captureScreen(name, AGENT_TUI_READY_LINES));
|
|
@@ -5788,31 +5874,36 @@ async function configureAgentInLock(name, model, effort, fast) {
|
|
|
5788
5874
|
}
|
|
5789
5875
|
if (model || effort) {
|
|
5790
5876
|
// `/model` はGrokが利用者の既定([models].default)へも書くので、切り替えの直前の値へ戻す。
|
|
5877
|
+
beforeChange();
|
|
5791
5878
|
await sendGrokModelCommand(name, meta, next ? `/model ${next}${effort ? ` ${effort}` : ""}` : `/effort ${effort}`, next, effort);
|
|
5792
5879
|
if (model) {
|
|
5793
5880
|
rememberModel();
|
|
5794
5881
|
recordAgentFast(meta, next !== model || modelIsFastVariant("grok", model));
|
|
5795
5882
|
}
|
|
5796
5883
|
}
|
|
5797
|
-
if (!model && fast !== null)
|
|
5884
|
+
if (!model && fast !== null) {
|
|
5885
|
+
beforeChange();
|
|
5798
5886
|
recordAgentFast(meta, await switchGrokFast(name, meta, fast));
|
|
5887
|
+
}
|
|
5799
5888
|
return configured();
|
|
5800
5889
|
}
|
|
5801
5890
|
// `/model` の選択は、利用者のconfig.tomlへ model と model_reasoning_effort を既定として保存する。席だけの替えにするため、直前の値へ戻す。
|
|
5802
5891
|
if (model || effort) {
|
|
5803
|
-
await keepingCodexDefaults(meta.agent_executable ?? resolveAgentBin("codex"), meta.codex_home ?? realCodexHome(), ["model", "model_reasoning_effort"], () => configureCodexModel(name, model, effort));
|
|
5892
|
+
await keepingCodexDefaults(meta.agent_executable ?? resolveAgentBin("codex"), meta.codex_home ?? realCodexHome(), ["model", "model_reasoning_effort"], () => configureCodexModel(name, model, effort, beforeChange));
|
|
5804
5893
|
}
|
|
5805
5894
|
rememberModel();
|
|
5806
|
-
if (fast !== null)
|
|
5895
|
+
if (fast !== null) {
|
|
5896
|
+
beforeChange();
|
|
5807
5897
|
recordAgentFast(meta, await switchCodexFast(name, meta, fast, fastVerified));
|
|
5898
|
+
}
|
|
5808
5899
|
else
|
|
5809
5900
|
await dropFastIfUnsupported();
|
|
5810
5901
|
return configured();
|
|
5811
5902
|
}
|
|
5812
5903
|
/** Codexの `/model` の選ぶ画面で、modelとreasoning effortを替える。 */
|
|
5813
|
-
async function configureCodexModel(name, model, effort) {
|
|
5904
|
+
async function configureCodexModel(name, model, effort, beforeChange) {
|
|
5814
5905
|
try {
|
|
5815
|
-
await chooseCodexModel(name, model, effort);
|
|
5906
|
+
await chooseCodexModel(name, model, effort, beforeChange);
|
|
5816
5907
|
}
|
|
5817
5908
|
catch (error) {
|
|
5818
5909
|
// 選べずに断る時は、開いた選ぶ画面を閉じてから断る(開いたままだと、席は次の文を受け付けない)。
|
|
@@ -5826,16 +5917,31 @@ async function configureCodexModel(name, model, effort) {
|
|
|
5826
5917
|
throw error;
|
|
5827
5918
|
}
|
|
5828
5919
|
}
|
|
5829
|
-
async function chooseCodexModel(name, model, effort) {
|
|
5920
|
+
async function chooseCodexModel(name, model, effort, beforeChange) {
|
|
5921
|
+
const beforeCounts = lineCounts(captureScreen(name, AGENT_TUI_READY_LINES));
|
|
5830
5922
|
await sendAgentPromptText(name, "/model");
|
|
5831
5923
|
const modelScreen = await waitForScreenText(name, "Select Model and Effort");
|
|
5832
5924
|
if (model) {
|
|
5833
|
-
|
|
5925
|
+
let choice = codexModelChoice(modelScreen, model);
|
|
5926
|
+
if (!choice) {
|
|
5927
|
+
const meta = loadAgentMetadata(name);
|
|
5928
|
+
const bin = meta.agent_executable ?? resolveAgentBin("codex");
|
|
5929
|
+
if (!bin)
|
|
5930
|
+
throw new AitermError("Codex の CLI が見つかりません", 2);
|
|
5931
|
+
const catalog = await codexModelChoices(bin, true);
|
|
5932
|
+
const target = catalog.models.find(item => item.id.toLowerCase() === model.toLowerCase());
|
|
5933
|
+
const displayName = target?.display_name;
|
|
5934
|
+
if (displayName && catalog.models.filter(item => item.display_name?.toLowerCase() === displayName.toLowerCase()).length === 1) {
|
|
5935
|
+
choice = codexModelChoice(modelScreen, model, displayName);
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5834
5938
|
if (!choice)
|
|
5835
5939
|
throw new AitermError(`Codexの/modelに ${model} がありません`, 2);
|
|
5940
|
+
beforeChange();
|
|
5836
5941
|
sendMenuChoice(name, choice);
|
|
5837
5942
|
}
|
|
5838
5943
|
else {
|
|
5944
|
+
beforeChange();
|
|
5839
5945
|
sendMenuChoice(name, "Enter");
|
|
5840
5946
|
}
|
|
5841
5947
|
let effortScreen = await waitForScreenText(name, "Select Reasoning Level");
|
|
@@ -5856,7 +5962,13 @@ async function chooseCodexModel(name, model, effort) {
|
|
|
5856
5962
|
else {
|
|
5857
5963
|
sendMenuChoice(name, "Enter");
|
|
5858
5964
|
}
|
|
5859
|
-
|
|
5965
|
+
for (const deadline = performance.now() + 3_000; performance.now() < deadline; await sleep(100)) {
|
|
5966
|
+
const screen = captureScreen(name, AGENT_TUI_READY_LINES);
|
|
5967
|
+
const counts = lineCounts(screen);
|
|
5968
|
+
if (codexModelChangeNotices(screen, model, effort).some(line => (counts.get(line) ?? 0) > (beforeCounts.get(line) ?? 0)))
|
|
5969
|
+
return;
|
|
5970
|
+
}
|
|
5971
|
+
throw new AitermError("CODEX_MODEL_SWITCH_UNCONFIRMED: 指定したmodel/effortの新しい変更通知を確認できません。設定が変わった可能性があります。再送しないでください。", 2);
|
|
5860
5972
|
}
|
|
5861
5973
|
export function __testCodexConfigureChoices(screen, model, effort) {
|
|
5862
5974
|
return {
|
package/dist/errors.js
CHANGED
package/dist/harnesses/codex.js
CHANGED
|
@@ -1000,14 +1000,18 @@ export function codexLaunchBlockingDialog(screen) {
|
|
|
1000
1000
|
return "起動時ダイアログ(種別未特定)";
|
|
1001
1001
|
return null;
|
|
1002
1002
|
}
|
|
1003
|
-
export function codexModelChoice(screen, model) {
|
|
1003
|
+
export function codexModelChoice(screen, model, displayName = null) {
|
|
1004
|
+
const choices = [];
|
|
1004
1005
|
for (const line of screen.slice(screen.lastIndexOf("Select Model and Effort")).split("\n")) {
|
|
1005
|
-
const match = line.match(/^\s*(?:›\s*)?(\d+)\.\s+(\
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1006
|
+
const match = line.match(/^\s*(?:›\s*)?(\d+)\.\s+(.+?)\s*$/);
|
|
1007
|
+
if (!match)
|
|
1008
|
+
continue;
|
|
1009
|
+
// Native labels can contain spaces; descriptions and the current marker are not part of the label.
|
|
1010
|
+
const label = match[2].split(/\s{2,}/)[0].replace(/\s+\(current\)$/, "");
|
|
1011
|
+
if ([model, displayName].some(name => name !== null && label.toLowerCase() === name.toLowerCase()))
|
|
1012
|
+
choices.push(match[1]);
|
|
1009
1013
|
}
|
|
1010
|
-
return null;
|
|
1014
|
+
return choices.length === 1 ? choices[0] : null;
|
|
1011
1015
|
}
|
|
1012
1016
|
export function codexEffortChoice(screen, effort) {
|
|
1013
1017
|
const labels = {
|
|
@@ -1028,6 +1032,12 @@ export function codexEffortChoice(screen, effort) {
|
|
|
1028
1032
|
}
|
|
1029
1033
|
return null;
|
|
1030
1034
|
}
|
|
1035
|
+
export function codexModelChangeNotices(screen, model, effort) {
|
|
1036
|
+
return screen.split("\n").map(line => line.trim()).filter(line => {
|
|
1037
|
+
const match = line.match(/^(?:[•◦]\s*)?Model changed to (\S+)(?: (none|minimal|low|medium|high|xhigh|max|ultra)\b)?/);
|
|
1038
|
+
return match !== null && (!model || match[1].toLowerCase() === model.toLowerCase()) && (!effort || match[2] === effort);
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1031
1041
|
export function codexMoreReasoningChoice(screen) {
|
|
1032
1042
|
for (const line of screen.split("\n")) {
|
|
1033
1043
|
const match = line.match(/^\s*(?:›\s*)?(\d+)\.\s+More reasoning/);
|
package/dist/harnesses/cursor.js
CHANGED
|
@@ -256,6 +256,9 @@ export async function observeCursorDone(meta, timeout, requestedCursor, readScre
|
|
|
256
256
|
// 最初の周回では必ず読む(timeout=0の照会も1回は読む)。
|
|
257
257
|
if (screenDue()) {
|
|
258
258
|
const screen = readScreen(meta.aiterm_session);
|
|
259
|
+
const providerFailure = cursorProviderFailure(screen);
|
|
260
|
+
if (providerFailure)
|
|
261
|
+
return observation("error", null, null, providerFailure.message, providerFailure.kind);
|
|
259
262
|
const limited = cursorUsageLimit(screen)?.message ?? null;
|
|
260
263
|
if (limited)
|
|
261
264
|
return observation("rate_limited", null, limited);
|
|
@@ -474,7 +477,7 @@ export function assertCursorModelAvailable(bin, cwd, model, effort, fast = false
|
|
|
474
477
|
if (fast && !models.includes(effective)) {
|
|
475
478
|
throw new FastModeError("FAST_MODE_NOT_SUPPORTED", `Cursor の一覧に ${JSON.stringify(effective)} がありません(model=${model}${effort ? `、reasoning_effort=${effort}` : ""} のfast版)。起動していません。`);
|
|
476
479
|
}
|
|
477
|
-
const available = effort || fast ? models.includes(effective) : models.includes(model) || models.some((id)
|
|
480
|
+
const available = effort || fast ? models.includes(effective) : models.includes(model) || models.some(id => cursorBaseModel(id)?.base === model);
|
|
478
481
|
if (!available) {
|
|
479
482
|
throw new AitermError(`Cursor model catalog に ${JSON.stringify(effective)} がありません。` +
|
|
480
483
|
"modelとreasoning_effortから作る正規IDが存在しないため、別modelへfallbackせず中止しました", 2);
|
|
@@ -566,6 +569,27 @@ export function cursorTuiReady(screen) {
|
|
|
566
569
|
return true;
|
|
567
570
|
return /Cursor Agent/i.test(screen) && CURSOR_COMPOSER_MARKER_RE.test(screen);
|
|
568
571
|
}
|
|
572
|
+
/** Current official billing refusal, not an idle/completed turn or an authentication error. */
|
|
573
|
+
export function cursorProviderFailure(screen) {
|
|
574
|
+
const clean = screen.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
575
|
+
const heading = [...clean.matchAll(/^[ \t]*Error:[ \t]*[^\n]*/gim)].at(-1);
|
|
576
|
+
if (!heading)
|
|
577
|
+
return null;
|
|
578
|
+
const current = clean.slice(heading.index);
|
|
579
|
+
const after = clean.slice(heading.index + heading[0].length);
|
|
580
|
+
if (cursorTuiBusy(after) || CURSOR_FOLLOWUP_MARKER_RE.test(after) || CURSOR_START_PROMPT_MARKER_RE.test(after)
|
|
581
|
+
|| after.split("\n").some(line => CURSOR_COMPOSER_CONTENT_MARKER_RE.test(line)))
|
|
582
|
+
return null;
|
|
583
|
+
try {
|
|
584
|
+
const payload = JSON.parse(current.slice(current.indexOf(":") + 1).trim());
|
|
585
|
+
if (payload?.error?.code !== "prepaid_balance_exhausted")
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
return { kind: "prepaid_balance_exhausted", message: "Cursor: prepaid_balance_exhausted" };
|
|
592
|
+
}
|
|
569
593
|
// 利用上限に達したCursorは、入力欄も戻さずに説明を出して止まる(2026.09.26-dd393fe、macOSで実測)。
|
|
570
594
|
// transcriptには、user turnを残さずにturn_ended(status "error")だけを書く事がある(実記録で8件)。その時は完了の条件
|
|
571
595
|
// (user turnが増えている)に当たらないので、画面で見る。user turnがある時は、完了待ちが記録から読む(cursorTurnError)。
|
|
@@ -623,6 +647,9 @@ export function cursorPromptHooksRunning(screen) {
|
|
|
623
647
|
}
|
|
624
648
|
export function cursorPaneObservation(screen) {
|
|
625
649
|
const tail = screen.split("\n").slice(-32).join("\n");
|
|
650
|
+
const providerFailure = cursorProviderFailure(tail);
|
|
651
|
+
if (providerFailure)
|
|
652
|
+
return { state: "blocked", reason: providerFailure.kind, detail: providerFailure.message };
|
|
626
653
|
if (cursorUsageLimit(tail))
|
|
627
654
|
return { state: "blocked", reason: "rate_limited" };
|
|
628
655
|
const hookBlocked = cursorHookBlocked(tail);
|
package/dist/harnesses/grok.js
CHANGED
|
@@ -284,6 +284,7 @@ export async function observeGrokDone(meta, timeout, requestedCursor, detectRate
|
|
|
284
284
|
let initializedBoundary = false;
|
|
285
285
|
let turnStarted = false;
|
|
286
286
|
let unacceptedSeen = 0;
|
|
287
|
+
let pendingError = null;
|
|
287
288
|
const deadline = performance.now() + timeout * 1000;
|
|
288
289
|
const rateLimitDue = pollGate(AGENT_RATE_LIMIT_POLL_MS);
|
|
289
290
|
const observation = (outcome, ev = null, rateLimit = null, error = null) => ({
|
|
@@ -339,13 +340,18 @@ export async function observeGrokDone(meta, timeout, requestedCursor, detectRate
|
|
|
339
340
|
}
|
|
340
341
|
try {
|
|
341
342
|
const record = JSON.parse(line);
|
|
342
|
-
if (record?.type === "turn_started")
|
|
343
|
+
if (record?.type === "turn_started") {
|
|
343
344
|
turnStarted = true;
|
|
345
|
+
pendingError = null;
|
|
346
|
+
}
|
|
344
347
|
const done = grokCompletionEvent(meta, record);
|
|
345
348
|
if (done) {
|
|
346
349
|
const limited = done.done_status === "turn_error"
|
|
347
350
|
? detectRateLimit(meta.kind, meta.aiterm_session) : null;
|
|
348
|
-
|
|
351
|
+
if (done.done_status === "turn_error" && !limited && timeout > 0 && performance.now() < deadline)
|
|
352
|
+
pendingError = { event: done, until: Math.min(deadline, performance.now() + AGENT_DONE_POLL_MS) };
|
|
353
|
+
else
|
|
354
|
+
return observation(limited ? "rate_limited" : done.done_status === "turn_error" ? "error" : "done", done, limited);
|
|
349
355
|
}
|
|
350
356
|
}
|
|
351
357
|
catch {
|
|
@@ -354,6 +360,23 @@ export async function observeGrokDone(meta, timeout, requestedCursor, detectRate
|
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
362
|
}
|
|
363
|
+
if (pendingError) {
|
|
364
|
+
const remaining = pendingError.until - performance.now();
|
|
365
|
+
// shortcut: settle one existing poll after the error event; extend only with evidence of a longer native redraw.
|
|
366
|
+
if (remaining > 0) {
|
|
367
|
+
await sleep(remaining);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const limited = detectRateLimit(meta.kind, meta.aiterm_session);
|
|
371
|
+
if (!fs.existsSync(metadataFile))
|
|
372
|
+
return observation("closed");
|
|
373
|
+
if (safeStatSize(transcript) !== cursor) {
|
|
374
|
+
if (performance.now() >= deadline)
|
|
375
|
+
return observation("timeout");
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
return observation(limited ? "rate_limited" : "error", pendingError.event, limited);
|
|
379
|
+
}
|
|
357
380
|
// 質問カードの確認は画面を読む(tmuxを起動する)。完了の見回りより間隔を空け、最初の周回では必ず見る。
|
|
358
381
|
if (rateLimitDue()) {
|
|
359
382
|
const limited = detectRateLimit(meta.kind, meta.aiterm_session);
|
package/dist/index.js
CHANGED
|
@@ -176,6 +176,12 @@ export function createAitermServer(options = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
function fail(e) {
|
|
178
178
|
const msg = e instanceof Error ? e.message : String(e);
|
|
179
|
+
const configurationFailure = e instanceof Error ? e.configurationFailure : undefined;
|
|
180
|
+
if (configurationFailure)
|
|
181
|
+
return {
|
|
182
|
+
content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
|
183
|
+
structuredContent: { ...configurationFailure },
|
|
184
|
+
};
|
|
179
185
|
if (e instanceof AgentAuthenticationPreflightError)
|
|
180
186
|
return {
|
|
181
187
|
content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
package/docs/DESIGN.md
CHANGED
|
@@ -168,6 +168,10 @@ harnessがagent loop、認証、hook、session、transcript、model catalogを
|
|
|
168
168
|
project/user環境を置換せず、launch相関と完了回収に必要なstateだけを加える。
|
|
169
169
|
Throughlineの補足記憶はpathを透過搬送するだけで、内容、project束縛、context予算はThroughlineが所有する。
|
|
170
170
|
|
|
171
|
+
設定変更もnative catalogと標準入力操作を使う。Claudeのaliasと任意IDはcatalogの表示名へ結び、CodexはID表記がpickerに無い時に同じ公式catalogの表示名を使う。名前のprefixや任意の空白置換で別modelを選ばない。Cursorの素ID判定は既存effort variantの解析と一致させ、Grokの完成IDはそのまま渡す。
|
|
172
|
+
|
|
173
|
+
4harness共通の`agent_configure`は、変更を発行し得る境界に達したかを要求内で保持する。失敗は`aiterm.agent-configure-error.v1`の`not_applied/not_started`又は`outcome_unknown/possible`で返し、後者には部分適用を含む。これは要求単位の保守的な分類で、以前の実設定や他要求の状態は証明しない。成功型は維持し、Codexの完了は指定ID・effortに一致する新規native通知を確認する。別modelの通知や残画面では成功にしない。
|
|
174
|
+
|
|
171
175
|
agent turnは常に非ブロックdispatchであり、receiptの`event_cursor`がturn境界になる。
|
|
172
176
|
Codex親にはAitermのMCP processが完了を観測し、選択設定に応じて公式Steerまたはqueueへ本文を自動配送する。
|
|
173
177
|
Claude Code親は公式の非同期hookで本文を受け取り、待機中も新しいturnへ進める。
|
|
@@ -440,6 +444,7 @@ Codexが書いた種類は`error_kind`で返す。失敗を空の回答の完了
|
|
|
440
444
|
Cursorは、誤りで終わったturnを、記録の`turn_ended`へ`status: "error"`と文で書く。完了待ちは、利用上限の文を`rate_limited`、
|
|
441
445
|
席で止めたturn(`User aborted request`)を今までどおり`done`、ほかを`error`で返す。`error`は1行の文、文の頭の角括弧の名前は
|
|
442
446
|
`error_kind`で返す(ADR 0106)。判定と文の整え方は`src/harnesses/cursor.ts`が所有する。
|
|
447
|
+
Cursorの現在Error表示も同じharnessで解析し、完全なJSONの`error.code`が`prepaid_balance_exhausted`ならuser記録を待たずerrorへ進める。説明文のcodeや壊れたJSON、後続composer/busyを持つ旧表示は採用しない。stopの非busy保全は変更しない。
|
|
443
448
|
|
|
444
449
|
Grokのread-only sandbox起動拒否は、`src/harnesses/grok.ts`の
|
|
445
450
|
`assertGrokSandboxNotRejected`がCLIのエラー表示から検出する。`src/core.ts`の共通入力受付待機は
|
|
@@ -466,6 +471,7 @@ Grokの終了済みerrorターンにweekly-limit質問カードが残る場合
|
|
|
466
471
|
`grokRateLimitDialog`が見出しと操作footerの組を所有し、過去logや後続UIのあるカードは採用しない。
|
|
467
472
|
privacy案内は現在の枠付きcomposerとmodel footerが見える場合だけ入力受付を妨げない。
|
|
468
473
|
完了観測は成功eventを優先し、今回のerror eventと現在のカードが揃えばturn情報付きの`rate_limited`を返す。
|
|
474
|
+
Grokのerror eventが先に見え、上限panelがまだ無い場合、待機呼出しは既存の見回り一回分だけ後に現在panelを再確認する。上限が無ければ元のerrorを保ち、途中の次turn開始や元launch消失を再検査する。timeout=0の即時照会は待たない。遅い全描画の成功を保証せず、入力・provider要求を再送しない。
|
|
469
475
|
完了の見回りは100msで、画面を読む確認(利用上限の知らせ、Cursorのhook拒否の表示)は別の間隔で行う。画面を読むたびにtmuxを1回起動するため。
|
|
470
476
|
Claude・Grokは2秒、Cursorは1秒に1回で、待ちに入った最初の周回では必ず読む(ADR 0085)。
|
|
471
477
|
新turnの完了前に古いlogだけで上限を返さない。購入・再認証・過去prompt再送・定期再試行は行わない。
|
|
@@ -511,6 +517,10 @@ respondは既session send lock内で現在の空欄/段階と世代を再検証
|
|
|
511
517
|
|
|
512
518
|
Claude authのcurrent menuはharnessの単一parseがphase/rows/selected/入力占有を所有する。古いthemeと新loginが同viewportに残っても最後の現在phaseだけを採り、coreはそのselected_idでnavigateする。code欄が現在phaseならoccupied状態から古いmenu UIへ戻さない。cursor欠測/複数cursor/未知row/後続の未知promptは入力前拒否。Native内部の入力観測は公開auth_uiへ直接返さず、公開schemaを拡張しない。
|
|
513
519
|
|
|
520
|
+
Authorization-code readback observes the same metadata generation for up to three seconds after one submission. A later redraw may establish a waiting or other recognized stage; it does not establish authenticated status by itself. An unchanged code prompt, replaced metadata generation or failed readback retains unknown without another input.
|
|
521
|
+
|
|
522
|
+
Authentication process exit observation reads the native exit status and signal independently of PTY EOF. If EOF is visible before either terminal field is ready, the same metadata generation is observed for a three-second window; missing status at the deadline remains unconfirmed failure. Signals and nonzero exits stay failures. Exit0 still requires the official authentication status, with a generation recheck after that call. A disappeared or replaced session, including a pane returning live after EOF, is not adopted. Observation never restarts login or repeats input.
|
|
523
|
+
|
|
514
524
|
## CLI-owned goal adapter
|
|
515
525
|
|
|
516
526
|
`agent-goal.ts` owns typed I/O, operation preconditions, host provenance, and result/readback distinctions. `harnesses/codex-goal.ts` maps these operations to the official goal protocol and verifies the loaded thread. `codex-goal-connection.ts` owns the POSIX native rendezvous alias checks; `codex-relay-client.ts` supplies the existing WebSocket request transport with explicit experimental opt-in. `core.agentGoal` binds the original session/launch/harness process and shares existing send admission. No goal state or continuation loop is stored by Aiterm.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.22",
|
|
4
4
|
"mcpName": "io.github.kitepon/aiterm-mcp",
|
|
5
5
|
"description": "Persistent terminal MCP with one harness-based launcher for Claude Code, Codex CLI, Grok CLI, and Cursor Agent CLI, plus durable PTYs for SSH, containers, and REPLs.",
|
|
6
6
|
"keywords": [
|