import { type ProductProfile } from "./profile.js"; import { type CodexParent, type CodexReceiverRuntime } from "./codex-receiver.js"; /** 会話の記録(rollout)の末尾から読んだ、最後の番の状態。 */ export type CodexTurnTail = "running" | "completed" | "interrupted" | "none" | "unknown"; /** * 記録の末尾から、最後の番の境を読む。task_started=走っている、task_complete=普通に終わった、turn_aborted=途中で止められた。 * 番が1つも無ければ none。末尾16MiBに境が無い・読めない時は unknown(起こさない側へ倒す)。 */ export declare function readCodexTurnTail(file: string): CodexTurnTail; export declare function codexThreadUrl(threadId: string): string; export interface CodexThreadOpener { (url: string): { ok: boolean; detail?: string; }; } /** * Windowsで、このprocessが人の画面のあるsessionで動いているか。サービスやsshのsession(番号0)から開いたリンクは、人の画面のアプリへ届かない。 * sessionの番号を読めない時(PowerShell 7が無い)は、画面のあるsessionにだけ入る環境変数`SESSIONNAME`で見る。 */ export declare function windowsInteractiveSession(env?: NodeJS.ProcessEnv, sessionId?: () => string): boolean; /** * OSの口で、Codexのアプリにリンクを開かせる関数を返す。口の無い環境ではnull。 * macOSは`/usr/bin/open -g`(アプリを前面へ出さない)、Windowsは`cmd /c start`(人の画面のあるsessionの時だけ)。 * Linuxのアプリは、まだ起こせない(`xdg-open`で開かせても会話が載らなかった。実物で確かめた後に足す)。 * 命令は場所を決めて呼ぶ。CodexがMCP serverへ渡す環境は細く、PATHに頼ると見つからない事がある。 */ export declare function codexThreadOpener(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, interactive?: () => boolean): CodexThreadOpener | null; export type CodexWakeOutcome = /** 見直した時にはキューに無かった。会話が載っていて受け取ったか、hookが番の途中へ入れた。 */ "delivered" /** 番の途中。hookか、番の終わりの公式キューが渡す。 */ | "running" /** 最後の番が途中で止められている。人が次の文を送るまでCodexはキューを動かさない。起こさない。 */ | "interrupted" /** アプリの会話でない(CLIの席など)。リンクで開く相手が無い。 */ | "not_app_thread" /** 会話の記録から番の状態を読めなかった。起こさない。 */ | "unknown_state" /** この環境に、リンクを開く口が無い。 */ | "no_opener" /** リンクを開く命令が失敗した。 */ | "open_failed" /** リンクを開き、キューが動いた(この文が出た、または前に並んでいた文が出た)。 */ | "woken" /** リンクを開いたが、待った間にキューが動かなかった。 */ | "opened_still_queued"; export interface CodexWakeResult { delivery_id: string; thread_id: string; outcome: CodexWakeOutcome; /** 番の状態を読んだ時の値。読む前に決まった時はnull。 */ turn: CodexTurnTail | null; checked_at: string; opened_at: string | null; detail?: string; } export interface CodexWakeOptions { /** 入れてから見直すまで。載っている会話は、Codexが10秒以内に番にする。 */ delay_ms?: number; /** リンクを開いた後、キューが動くのを待つ長さ。 */ confirm_ms?: number; /** 同じ会話を、ほかの配送が開いたばかりの時に、重ねて開かない長さ。 */ reopen_guard_ms?: number; runtime?: CodexReceiverRuntime; /** nullは「口が無い」。省略すると、この環境の口を使う。 */ open?: CodexThreadOpener | null; sleep?: (ms: number) => Promise; /** 結果を残す場所。省略すると製品のhook directoryの`wake`。 */ directory?: string; } export declare function codexWakeDirectory(profile: ProductProfile): string; /** 配送の後に残した結果を読む。無ければnull。 */ export declare function readCodexWakeResult(profile: ProductProfile, deliveryId: string, directory?: string): CodexWakeResult | null; /** * 入れた文がまだキューにあり、会話が寝ている時に、アプリにその会話を開かせる。結果を返し、`directory`へ残す。 * 起こすのは、アプリの会話(sourceがvscode)で、最後の番が普通に終わっている(または番が1つも無い)時だけ。 */ export declare function wakeCodexParentIfAsleep(profile: ProductProfile, parent: CodexParent, deliveryId: string, options?: CodexWakeOptions): Promise; /** 見張りを別のprocessで起こすかどうか。リンクを開く口の無いOS(Linuxなど)では、何も起こさない。 */ export declare function codexWakeWatchEnabled(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): boolean; export declare const CODEX_WAKE_PAYLOAD_ENV = "AITERM_STEER_CODEX_WAKE_PAYLOAD"; /** 見張りのprocessへ渡す、関数を含まない製品の識別情報。 */ export declare function serializeWakeProfile(profile: ProductProfile): Record; /** * 配送を呼んだprocessとは別に、見張りを1つ起こす。呼んだprocessがすぐ終わっても(製品のCLI)、見直しと起こしは最後まで走る。 * 起こせなかった時も投げない。文はもうキューに入っていて、今までどおり会話が開かれた時に届く。 */ export declare function startCodexWakeWatch(profile: ProductProfile, parent: CodexParent, deliveryId: string, options?: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv; entry?: string; delay_ms?: number; }): boolean; /** 見張りのprocessの本体。結果は製品のhook directoryの`wake`に残す。 */ export declare function runCodexWakeMain(raw?: string | undefined): Promise;