UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

234 lines • 13.9 kB
/** * The `custom_unsupported` capability gate (plan tasks 13/14). * * In RPC mode `ctx.ui.custom` cannot render a third-party component — there is no * TUI to render it FROM. Historically it returned `undefined` synchronously with * NO wire message, so a default RPC client saw nothing at all. A client that * can present a native "this extension UI requires the classic TUI" notice opts * in via a capability flag. * * This gate is a PURE function so the additive-only guarantee is unit-provable: * only a client that advertised the `custom_unsupported` capability gets the * additive `extension_ui_request{method:"custom_unsupported"}` notice; every * other (default) client gets `undefined` — byte-identical to the prior * behavior, no extra bytes on the wire. */ import * as crypto from "node:crypto"; /** The capability string a client sends in its handshake to opt into the notice. */ export const CUSTOM_UNSUPPORTED_CAPABILITY = "custom_unsupported"; export const EXTENSION_EVENTS_CAPABILITY = "extension_events"; /** Host protocol support; a session without codemode returns `eval_cells_unavailable`. */ export const EVAL_CELLS_CAPABILITY = "eval_cells"; export const AUTO_TITLE_SESSIONS_CAPABILITY = "auto_title_sessions"; /** `unload_session { graceful, waitMs }` on a host and on a terminal's control endpoint (oh-my-openagent#14313). */ export const UNLOAD_GRACEFUL_CAPABILITY = "unload_graceful"; /** Host capability: the `continue_from_leaf` command starts a turn with no new prompt (#1930). */ export const CONTINUE_FROM_LEAF_CAPABILITY = "continue_from_leaf"; /** HOST capability: the shared router guards foreign holders at every writing RPC admission. */ export const SESSION_HELD_CAPABILITY = "session_held"; /** Host supports explicit held-wake release; its command reply acknowledges admission. */ export const RESUME_SESSION_CAPABILITY = "resume_session"; /** Host honors open_session.attended:false instead of silently starting unattended work. */ export const ATTENDED_CAPABILITY = "attended"; /** * Opt-in: the host replaces inline image bytes inside tool results with `image_ref` * placeholders for this connection; the client fetches a block on demand with `get_media`. */ export const MEDIA_PLACEHOLDERS_CAPABILITY = "media_placeholders"; /** * Opt-in, honored only behind `SENPI_ENGINE_SOCKET_COMPACT_UPDATES` and never advertised (S13; S17 owns the public * selection): a record past F reaches this connection as an `eventLease` envelope paged through `get_recovery_page`. */ export const COMPACT_EVENTS_CAPABILITY = "compact_events"; /** Opt-in: the client can present a multi-question `extension_ui_request{method:"question"}`. */ export const QUESTION_CAPABILITY = "question"; /** HOST capability: `prompt.toolBarrier` and `release_tool_barrier` are honored (senpi#3717). */ export const TOOL_BARRIER_CAPABILITY = "tool_barrier"; /** * Both directions, like `media_placeholders`: a host advertises it in `get_protocol_info` (its sessions send * `host_request` / `relocation_due`), and a client sends it in `set_client_info` to offer moving a session elsewhere. */ export const SESSION_RELOCATION_CAPABILITY = "session_relocation"; /** * HOST capability (advertised in `get_protocol_info`, never sent by a client): * this host honors `open_session.retain_on_disconnect`, so a session opened with * that flag survives its last client's disconnect instead of being closed with it. */ export const RETAIN_ON_DISCONNECT_CAPABILITY = "retain_on_disconnect"; /** An `open_session` that names a session file and no `cwd` works where that file's header says (senpi#6427). */ export const OPEN_SESSION_HEADER_CWD_CAPABILITY = "open_session_header_cwd"; /** * HOST capability: a connection that proved the launch key can `declare_delegation`, and the host then enforces its own * method-class table on every record of that connection before dispatch; `classify_record` answers (senpi#5632). */ export const DELEGATED_CONNECTION_CAPABILITY = "delegated_connection_v1"; /** * A host whose delegated connections take `declare_delegation.roles` (omo-relay-daemon#307): an authority word per * incarnation, `relayExec` and the `authority` receipt. */ export const DELEGATION_ROLES_CAPABILITY = "delegation_roles_v1"; /** A host-mode delegation may carry the forwarder-granted `peer_agent` role (senpi#6305). */ export const PEER_AGENT_ROLE_CAPABILITY = "peer_agent_role_v1"; /** A delegation may state `principal.sameAccount`, so that device's turns follow this host's own setting (senpi#6342). */ export const SAME_ACCOUNT_DELEGATION_CAPABILITY = "same_account_delegation_v1"; /** * Client opt-in (D11 S3-5): the connection renders the value-free `secret_input_notice` and `grant_select_notice` of a * raiser-only dialog another connection presents, and their `*_notice_settled` records. It never answers them. */ export const RAISER_NOTICE_CAPABILITY = "raiser_notice_v1"; /** * Advertised by a multi-session host that answers `detach_connection`: it drops every attachment the * asking connection holds and replies only once that is done, so a short-lived client can return knowing * no other connection will still see it attached (senpi#3238). */ export const DETACH_CONNECTION_CAPABILITY = "detach_connection"; /** * Connection role (senpi#3811): the connection may exercise a person's authority (Stop with intent, release a * pause). It does not decide input origin; that comes from the entry point. Declared per connection by the * client's own `set_client_info` and fixed at that first declaration (see `connection-roles.ts`). */ export const INTERACTIVE_USER_CAPABILITY = "interactive_user"; /** `get_state` and `get_entries` accept `observe: true` and then never count as an attachment (senpi#4267). */ export const OBSERVE_READS_CAPABILITY = "observe_reads"; /** `get_entries` accepts `before` and `tail` and answers `next_before` (senpi#4267). */ export const ENTRIES_TAIL_CAPABILITY = "entries_tail"; /** A terminal control endpoint serves the host's observe-and-drive command set (senpi#4267). */ export const TUI_OBSERVER_CAPABILITY = "tui_observer"; /** The connection owns this session as a task child; only it may pause or resume the session for its run (senpi#3811). */ export const TASK_PARENT_CAPABILITY = "task_parent"; /** * HOST capability: this host accepts `open_session.context`, hands it to that session's * extensions as `pi.sessionContext`, and republishes it on `list_sessions { include_workers: true }`. */ export const SESSION_CONTEXT_CAPABILITY = "session_context"; /** * HOST capability: this host accepts `open_session.kind`, publishes `kind` on every * `list_sessions` row, hides `worker` rows unless `include_workers` is set, and keeps a * worker session's lifecycle records on the connections attached to it. */ export const SESSION_KIND_CAPABILITY = "session_kind"; /** * Host capability: `subscribe_sessions` / `unsubscribe_sessions` (the `session_status` stream), a real * `session_opened` per created session, `set_session_context`, and one `loaded_surfaces_changed` per * connection per inventory digest. */ export const SESSION_STATUS_CAPABILITY = "session_status"; /** * HOST capability: this host honors `open_session.auto_title`, so a session can opt * into or out of engine-side titling independently of `--auto-title-sessions`. */ export const AUTO_TITLE_PER_SESSION_CAPABILITY = "auto_title_per_session"; /** * HOST capability: this host answers `warm` (senpi#2314) - it loads what the next `open_session` for a * cwd, kind and context needs without opening a session. Advertised only by an in-process runtime. */ export const WARM_CAPABILITY = "warm"; /** HOST capability: invisible speculative sessions and single-use claim, in-process registries only. */ export const PARK_CLAIM_CAPABILITY = "park_claim"; /** * HOST capability: this host honors `open_session.durableSessionId`, so a caller that already * owns a stable record id for the conversation can CREATE the session under that id and keep * one identity instead of maintaining a mapping. Ignored on resume, where the session file's * header id stays authoritative. */ export const DURABLE_SESSION_ID_CAPABILITY = "durable_session_id"; /** A headless engine with a hand directory: `list_hands` and `select_hand` (R4). */ export const HAND_SELECTION_CAPABILITY = "hand_selection"; /** * HOST capability: this engine runs the builtin `moved-path-guard` and resolves paths the OmO desktop moved * with its data home in `open_session`, schedule delivery and session-holder claims (senpi#2898). The desktop * resumes a moved thread only on a host that advertises it. */ export const MOVED_PATH_GUARD_CAPABILITY = "moved_path_guard"; /** * HOST capability: this host honors `open_session.promptSurface`, building each session's prompt for * the surface its opener renders on (`terminal` | `app`) instead of only the process-wide * `SENPI_PROMPT_SURFACE`. A later open that names another surface rebuilds that session's prompt. */ export const PROMPT_SURFACE_CAPABILITY = "prompt_surface"; /** * HOST capability: this host honors `open_session.browserEngine` (`connected` | `builtin` | `none`). The * choice is per session, never per process: that session's tool subprocesses and eval kernel see * `OMO_BROWSER_ENGINE=<value>` and no other session on the host does. Advertised only because the * value reaches every consumer, so a client may rely on it the moment it sees this name. */ export const BROWSER_ENGINE_CAPABILITY = "browser_engine"; /** * HOST capability: every session on this host registers its host tools (show_html_page) through * `attachHostTools`, so a host bridge can route their calls to an app that serves them, and the * public SDK exports the writer such an app calls back (`writeHtmlPage`). A client offers a host * tool attachment only to a host that names this (senpi#5045). */ export const HOST_TOOLS_CAPABILITY = "host_tools"; /** * HOST capability: this host honors `open_session.env` (senpi#4381), the per-spawn caller env channel. * The entries are that session's own: its tool subprocesses see them, they are never merged into the host * process environment or carried to a successor generation through it, and only a task child opened with * `spawnedBy` naming that session inherits them (any client that could attach to it can open such a child). * A name outside the host's caller-passable set is refused with `invalid_session_env`. */ export const SESSION_ENV_CAPABILITY = "session_env"; /** * HOST capability: this host honors `open_session.retryFallback` (`{ modelFallback, fallbackChains }`). The * policy is that session's own: it is applied as an in-memory settings override for that session only, * never written to a settings file and never seen by another session on the host. */ export const RETRY_FALLBACK_PROFILE_CAPABILITY = "retry_fallback_profile"; /** * SINGLE-SESSION capability: this `--mode rpc` process accepts `set_retry_fallback` (the * `open_session.retryFallback` shape) before its first turn, so a caller that spawns one process per * session can give it its own fallback chain without a settings file. */ export const RETRY_FALLBACK_COMMAND_CAPABILITY = "retry_fallback_command"; /** * HOST capability: `open_session.promptSurface` also accepts `chat` (a chat bridge: no routing line, * no handoff block, no todo cues). A host without it refuses `chat` with `invalid_launch_profile`, * so a gateway sends `chat` only after seeing this and otherwise falls back to `app`. */ export const PROMPT_SURFACE_CHAT_CAPABILITY = "prompt_surface_chat"; /** * Env var carrying client capabilities to a single-connection stdio RPC host * (comma-separated). A launcher may set it from a client handshake; a plain * stdio client leaves it unset and sees byte-identical default behavior. * Owned by the host hand-off list, which keeps it out of agent children (senpi#7034). */ export { RPC_CLIENT_CAPABILITIES_ENV } from "./host-identity-env.js"; /** Parse the comma-separated capabilities env value into a trimmed list. */ export function parseClientCapabilities(value) { if (!value) return []; return value .split(",") .map((part) => part.trim()) .filter((part) => part.length > 0); } /** Fallback label when the calling extension's name cannot be determined. */ export const DEFAULT_CUSTOM_EXTENSION_LABEL = "custom UI component"; /** * Build the additive `custom_unsupported` request for a `ctx.ui.custom` call, or * `undefined` when the client did not opt in. * * Returning `undefined` is the load-bearing default-client path: the caller must * emit NOTHING in that case, preserving the exact prior wire behavior. */ export function buildCustomUnsupportedRequest(capabilities, extensionName) { if (!capabilities?.includes(CUSTOM_UNSUPPORTED_CAPABILITY)) { return undefined; } const name = extensionName.trim() || DEFAULT_CUSTOM_EXTENSION_LABEL; return { type: "extension_ui_request", id: crypto.randomUUID(), method: "custom_unsupported", extensionName: name, }; } /** `verify_api_key` and `keyHint` on `get_auth_providers` rows (desktop #2510). */ export const AUTH_KEY_VERIFY_CAPABILITY = "auth_key_verify"; /** `test_provider_account`: re-run the sign-in connection test on one Claude subscription account (senpi#4436). */ export const PROVIDER_ACCOUNT_TEST_CAPABILITY = "provider_account_test"; /** `account_reset`: reset one named account's local health, keeping its credentials (senpi#4879, senpi#5698). */ export const ACCOUNT_RESET_CAPABILITY = "account_reset"; /** Queued inputs carry a `revision`, and `dequeue_message` / `edit_queued_message` accept `expectedRevision` (senpi#3459). */ export const QUEUED_MESSAGE_REVISION_CAPABILITY = "queued_message_revision"; //# sourceMappingURL=custom-capability.js.map