@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
127 lines • 6.83 kB
TypeScript
/**
* The `schedule_wakeup` model tool: the ONLY model-callable surface of the `/loop`
* extension. It lets a dynamic (self-paced) loop pick its own next delay, or end itself.
*
* Exposure: the tool is registered `exposure: "search"` with lazy activation disabled, so it is
* absent from the resident tool list (and from `tool_search`) until the loop extension activates it
* for a live dynamic loop and retires it when that loop ends. Outside a dynamic loop every call is
* an error, so a resident registration only cost prompt tokens.
*
* Two deliberate shape decisions:
* - The TypeBox schema is a FLAT object with no root union. Several provider payload
* conversions rebuild tool schemas from top-level `properties` only, so a root
* `anyOf` would reach the model as an empty schema (same reasoning as
* `terminal/tools/monitor.ts`). Branch requirements are enforced in `execute`.
* - `delaySeconds` carries NO schema `minimum`/`maximum`. The contract clamps
* out-of-range integers instead of rejecting them, and schema bounds would make the
* clamp unreachable.
*
* Scheduler state is never mutated here: every effect goes through the injected
* `ScheduleWakeupSchedulerPort`.
*/
import { Type } from "typebox";
import type { ExtensionAPI } from "../../types.ts";
import type { EpochMs, LoopId, WakeupId } from "./types.ts";
/** Model-visible tool name. */
export declare const SCHEDULE_WAKEUP_TOOL = "schedule_wakeup";
/** Inclusive bounds the executor clamps `delaySeconds` into. */
export declare const MIN_WAKEUP_DELAY_SECONDS = 60;
export declare const MAX_WAKEUP_DELAY_SECONDS = 3600;
export declare const SCHEDULE_WAKEUP_DESCRIPTION = "Schedule when to resume work in /loop dynamic mode. Always pass the `prompt` argument unless stopping. Call this as the last action before ending a dynamic loop iteration so the loop remains alive; call with `stop: true` to end the active dynamic loop immediately.\n\n`delaySeconds` is clamped to 60-3600 seconds; 1200-1800 is the normal idle range, and a short delay chosen merely to poll loses prompt-cache value on many API paths. When a monitor or task notification is the primary wake source, the scheduled delay is only a fallback heartbeat.\n\nFor normal dynamic re-entry, set `prompt` to the complete original command, for example `/loop check the deploy`, preserving the user's text verbatim. Set `noop: true` only when this iteration found no actionable change; consecutive noop iterations are folded in the terminal view. Omit `noop` when stopping. Notify the user only when state changes in a way worth acting on, not once per tick.";
export declare const scheduleWakeupSchema: Type.TObject<{
delaySeconds: Type.TOptional<Type.TInteger>;
reason: Type.TString;
prompt: Type.TOptional<Type.TString>;
stop: Type.TOptional<Type.TBoolean>;
noop: Type.TOptional<Type.TBoolean>;
}>;
/** Runtime-validated parameter shape; the schema itself stays flat and permissive. */
export interface ScheduleWakeupParams {
readonly delaySeconds?: number;
readonly reason: string;
readonly prompt?: string;
readonly stop?: boolean;
readonly noop?: boolean;
}
export interface ScheduleWakeupScheduledDetails {
readonly ok: true;
readonly action: "scheduled";
readonly loopId: LoopId;
readonly wakeupId: WakeupId;
readonly replacedWakeupId?: WakeupId;
/** Integer the model asked for, before the clamp. */
readonly requestedDelaySeconds: number;
/** Effective delay after clamping to `[60, 3600]`. */
readonly delaySeconds: number;
readonly clamped: boolean;
readonly dueAt: EpochMs;
readonly reason: string;
/** Preserved verbatim after the non-blank check. */
readonly prompt: string;
readonly noop: boolean;
readonly noopStreak: number;
}
export interface ScheduleWakeupStoppedDetails {
readonly ok: true;
readonly action: "stopped";
readonly loopId: LoopId;
readonly terminalReason: "stopped";
readonly reason: string;
readonly endedAt: EpochMs;
/** Fields accepted for model compatibility but not applied. */
readonly ignoredFields: readonly ScheduleWakeupIgnorableField[];
}
export type ScheduleWakeupIgnorableField = "delaySeconds" | "prompt";
export type ScheduleWakeupDetails = ScheduleWakeupScheduledDetails | ScheduleWakeupStoppedDetails;
/**
* Which loop, if any, this tool call belongs to. `null` means no loop context at all;
* a `fixed` target means the call came from a fixed tick, whose schedule re-arms itself.
*/
export type ScheduleWakeupTarget = {
readonly kind: "dynamic" | "fixed";
readonly loopId: LoopId;
} | null;
export interface ScheduleWakeupRequest {
readonly loopId: LoopId;
readonly requestedDelaySeconds: number;
readonly delaySeconds: number;
readonly reason: string;
readonly prompt: string;
readonly noop: boolean;
}
export interface ScheduleWakeupOutcome {
readonly wakeupId: WakeupId;
/** Set when this schedule replaced a still-pending wakeup for the same loop. */
readonly replacedWakeupId?: WakeupId;
readonly dueAt: EpochMs;
readonly noopStreak: number;
}
export interface StopDynamicLoopRequest {
readonly loopId: LoopId;
readonly reason: string;
}
export interface StopDynamicLoopOutcome {
readonly endedAt: EpochMs;
}
/**
* Minimal scheduler surface this tool needs. Declared locally so the tool module stays
* independent of the scheduler implementation and testable with a fake.
*/
export interface ScheduleWakeupSchedulerPort {
/** Loop the current turn is attributed to, resolved at call time. */
getWakeupTarget(): ScheduleWakeupTarget;
scheduleWakeup(request: ScheduleWakeupRequest): Promise<ScheduleWakeupOutcome>;
stopDynamicLoop(request: StopDynamicLoopRequest): Promise<StopDynamicLoopOutcome>;
}
export interface LoopToolRegistrationDeps {
readonly scheduler: ScheduleWakeupSchedulerPort;
}
export declare const NO_ACTIVE_DYNAMIC_LOOP_ERROR = "schedule_wakeup can only be used while a dynamic /loop is active.";
export declare const FIXED_TICK_ERROR = "This is a fixed /loop tick; the recurring schedule re-arms automatically. Do not call schedule_wakeup.";
export declare const MISSING_PROMPT_ERROR = "prompt is required and must be non-empty unless stop is true.";
export declare const MISSING_DELAY_ERROR = "delaySeconds is required unless stop is true.";
export declare const NON_INTEGER_DELAY_ERROR = "delaySeconds must be a finite integer number of seconds.";
export declare const BLANK_REASON_ERROR = "reason is required and must be non-empty.";
export declare const NOOP_WITH_STOP_ERROR = "noop must be omitted when stop is true.";
export declare function registerLoopTools(pi: ExtensionAPI, deps: LoopToolRegistrationDeps): void;
//# sourceMappingURL=tools.d.ts.map