@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
96 lines • 5.79 kB
TypeScript
import { type CursorCliOauthExecutionMode } from "./settings.ts";
/**
* Guardrails for unattended Cursor CLI execution.
*
* The Cursor CLI runs its own tools the moment `--force` is on the argv, so
* that decision is never implicit: it requires the explicit
* `noApprovalAcknowledgedAt` acknowledgement, plan mode never forces, and a
* disabled force merely warns. Command denylists ride along through the
* per-account HOME's `cli-config.json`, strictly in the probe-proven shape
* (task 2: `permissions.deny` with exact full-command `Shell(...)` entries).
*/
/** Sandbox modes the installed CLI accepts (task 2 probe: allowed choices are exactly these). */
export declare const CURSOR_CLI_OAUTH_SANDBOX_MODES: readonly ["enabled", "disabled"];
export declare const CURSOR_CLI_OAUTH_NO_APPROVAL_EXPLANATION = "The Cursor CLI executes its own tools autonomously: with --force there is no senpi approval, no senpi sandboxing, and no tool-level audit for what it runs.";
export declare const CURSOR_CLI_OAUTH_ACKNOWLEDGEMENT_STEP = "Set \"cursorCliOauthProvider.noApprovalAcknowledgedAt\" to the current ISO-8601 timestamp (for example \"2026-08-17T12:00:00.000Z\") in senpi settings to acknowledge this once.";
/** One warning per session when force is disabled in agent mode (contracts block, task 18). */
export declare const CURSOR_CLI_OAUTH_FORCE_DISABLED_WARNING = "cursor-cli-oauth: forceExecution is disabled in agent mode, so the Cursor CLI will auto-reject every tool call; set executionMode to \"plan\" for planning turns that do not need execution.";
export type CursorCliGuardrailWarningCode = "force_execution_disabled" | "sandbox_mode_ignored" | "deny_command_rejected";
export type CursorCliGuardrailWarning = {
readonly kind: "warning";
readonly code: CursorCliGuardrailWarningCode;
readonly message: string;
};
export type CursorCliExecutionRefusal = {
readonly kind: "refusal";
readonly code: "no_approval_acknowledgement_required";
readonly message: string;
readonly acknowledgementStep: string;
};
export type CursorCliGuardrailSession = {
/** Every warning emitted so far in this session; one-time gates live here. */
readonly warnings: readonly CursorCliGuardrailWarning[];
/** Emit a warning once per deduplication key; returns whether it was emitted. */
warn(code: CursorCliGuardrailWarningCode, message: string, key?: string): boolean;
/** Validate a sandbox mode against the probe-proven allowlist, warning once per rejected value. */
validateSandboxMode(value: string | undefined): string | undefined;
};
export declare function createCursorCliGuardrailSession(): CursorCliGuardrailSession;
export type CursorCliExecutionPolicyInput = {
readonly forceExecution: boolean;
readonly noApprovalAcknowledgedAt: string | undefined;
readonly executionMode: CursorCliOauthExecutionMode;
readonly sandboxMode: string | undefined;
};
export type CursorCliExecutionDecision = {
readonly status: "refused";
readonly refusal: CursorCliExecutionRefusal;
} | {
readonly status: "allowed";
readonly force: boolean;
readonly executionMode: CursorCliOauthExecutionMode;
readonly sandboxMode: string | undefined;
readonly denyCommands: readonly string[];
/** Warnings accumulated in the session so far (not only this decision). */
readonly warnings: readonly CursorCliGuardrailWarning[];
};
/** Typed refusal for an unacknowledged force attempt; never confused with a warning. */
export declare class CursorCliExecutionRefusalError extends Error {
readonly code: "no_approval_acknowledgement_required";
readonly refusal: CursorCliExecutionRefusal;
constructor(refusal: CursorCliExecutionRefusal);
}
export declare function sanitizeCursorCliDenyCommands(entries: readonly string[], warn?: (message: string) => void): readonly string[];
/**
* Decide whether a turn may run unattended.
*
* - `--force` is emitted only in agent mode, only when force is requested, and
* only after `noApprovalAcknowledgedAt` is set; otherwise the decision is a
* typed refusal naming the acknowledgement step.
* - Plan mode never emits `--force` (the CLI only plans), so it needs no
* acknowledgement.
* - Force disabled in agent mode is allowed but warns once per session.
* - Unproven sandbox modes are ignored with one warning per distinct value.
*/
/**
* True while the settings guarantee an unattended agent-mode refusal: force is
* requested outside plan mode but `noApprovalAcknowledgedAt` was never set.
* Shared by the execution policy and the fallback-eligibility hook so the two
* can never disagree about when the lane refuses.
*/
export declare function cursorCliForceRefusalPending(input: Pick<CursorCliExecutionPolicyInput, "forceExecution" | "noApprovalAcknowledgedAt" | "executionMode">): boolean;
export declare function resolveCursorCliExecutionPolicy(input: CursorCliExecutionPolicyInput, session: CursorCliGuardrailSession, denyCommands?: readonly string[]): CursorCliExecutionDecision;
/**
* Pre-spawn hook: (re-)apply the deny list to the sandbox HOME's
* `cli-config.json`.
*
* The CLI rewrites this file during every invocation (task 2 observed its own
* keys appearing and `cli-config.json.bad` sidecars for malformed content), so
* this must run immediately before each spawn, composing with the home-store
* prepare pass that re-writes `auth.json` on the same cadence. Writes only the
* probe-proven shape (`permissions.deny` with exact `Shell(<full command>)`
* entries) and preserves every CLI-owned key already present. Writes nothing
* when no deny commands are configured.
*/
export declare function applyCursorCliDenyConfig(home: string, denyCommands: readonly string[]): void;
//# sourceMappingURL=guardrails.d.ts.map