UNPKG

@code-yeongyu/senpi

Version:

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

88 lines • 5.01 kB
import { StringEnum } from "@earendil-works/pi-ai"; import { Type } from "typebox"; export const DEFAULT_MONITOR_TIMEOUT_MS = 300_000; export const MAX_MONITOR_TIMEOUT_MS = 3_600_000; /** * One flat object schema, no top-level union: several provider payload paths * (e.g. Anthropic's legacy input_schema conversion) rebuild tool schemas from * top-level `properties` only, so a root anyOf would reach the model as an * empty schema. Branch requirements are enforced at runtime in `execute`. */ export const monitorSchema = Type.Object({ action: Type.Optional(StringEnum(["create", "rearm"], { description: "Defaults to create. rearm resumes a monitor paused by the wake budget or the runaway guard.", })), type: Type.Optional(StringEnum(["command", "path", "rpc"], { description: "Create: which source to watch; inferred when omitted (command -> command, path -> path, target -> rpc).", })), target: Type.Optional(Type.String({ minLength: 1, description: 'Create, rpc branch: "children" (sessions this one spawned, including ones spawned later), "all" (every session on every host and terminal of this user) or one session id, path or st_ task id; a session on another device is <device>/<session> (e.g. "laptop/abc123").', })), events: Type.Optional(Type.Union([Type.Literal("all"), Type.Array(Type.String({ minLength: 1 }))], { description: 'Rpc branch: record kinds to report, any RPC record type; default ["session_status"] (children: plus "effect_status"); "all" reports every kind, streaming collapsed to one line per 2 s.', })), exclude: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { description: 'Rpc branch with events "all": record kinds to drop.' })), description: Type.Optional(Type.String({ minLength: 1, maxLength: 200, description: "Create (required): specific label shown with every event, e.g. 'errors in deploy.log'.", })), command: Type.Optional(Type.String({ description: "Create, command branch (XOR path): shell command to run and watch in a PTY-backed monitor session.", })), path: Type.Optional(Type.String({ minLength: 1, description: "Create, file branch (XOR command): one regular file to watch natively, whose parent directory must already exist; takes no filter.", })), event: Type.Optional(StringEnum(["create", "modify"], { description: "File branch only: which file event fires the watch (defaults to create).", })), filter: Type.Optional(Type.String({ description: "Only lines matching this regex become monitor events (command output lines, rpc event lines).", })), timeout_ms: Type.Optional(Type.Number({ minimum: 1, maximum: MAX_MONITOR_TIMEOUT_MS, description: "Watcher deadline in milliseconds (default 300000; ignored when persistent).", })), persistent: Type.Optional(Type.Boolean({ description: "Standing watch: no deadline, and it survives a session restart (command re-run once, file rescanned and any detached change reported). Expires 7 days after creation; no per-session cap unless the terminal.maxDurableMonitors setting sets one; stop one with kill_bash.", })), bash_id: Type.Optional(Type.String({ description: "Rearm: paused monitor id (mon_ or bash_id) to resume; omit for all paused." })), wakes_per_hour: Type.Optional(Type.Integer({ minimum: 1, maximum: 3600, description: "Persistent command branch only: average wakes an hour for this watch (default: terminal.monitorWakesPerHour, 12). Lines matched between wakes are batched into the next one, never dropped; raise it for a chat bridge that needs quicker replies.", })), human_input: Type.Optional(Type.Boolean({ description: "Command branch only: set true when each output line is a message a person wrote (a chat or inbox bridge). Its deliveries then count as new user input, so a running goal keeps going; leave unset for machine status.", })), }); export function isFileCreateInput(input) { return (typeof input.description === "string" && input.description.length > 0 && typeof input.path === "string" && input.path.length > 0); } export function isCreateInput(input) { return (typeof input.description === "string" && input.description.length > 0 && typeof input.command === "string" && input.command.length > 0); } export function resolveDimension(value, fallback) { if (value === undefined || !Number.isFinite(value) || value < 1) return fallback; return Math.trunc(value); } export function resolveTimeoutMs(value) { const timeout = value ?? DEFAULT_MONITOR_TIMEOUT_MS; return Math.min(Math.max(Math.trunc(timeout), 1), MAX_MONITOR_TIMEOUT_MS); } export function compileFilter(filter) { if (filter === undefined) return undefined; return new RegExp(filter); } //# sourceMappingURL=monitor-schema.js.map