UNPKG

@code-yeongyu/senpi

Version:

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

37 lines • 1.7 kB
/** Fixed guidance only: errors from this boundary never carry the input or an underlying cause. */ export class SecretInputUnavailableError extends Error { constructor(reason) { super("This client cannot collect a secret; use the TUI or the host's settings route."); this.code = "secret_input_unavailable"; this.name = "SecretInputUnavailableError"; this.reason = reason; } } export function resolveSecretInputTimeout(opts) { const requested = opts?.timeout ?? 30 * 60 * 1000; if (!Number.isFinite(requested) || requested <= 0) throw new Error("Invalid secret input timeout"); // Whole milliseconds, and a deadline that stays a safe integer: the sealed binding signs `deadlineAtMs` (D11 5.3). const timeout = Math.ceil(requested); if (!Number.isSafeInteger(Date.now() + timeout)) throw new Error("Invalid secret input timeout"); return timeout; } /** Platform timers clamp delays above 2^31-1; recheck the original deadline rather than renewing it. */ export function armSecretInputDeadline(deadline, expire) { let timer; const check = () => { const remaining = deadline - Date.now(); if (remaining <= 0) expire(); else timer = setTimeout(check, Math.min(remaining, 2 ** 31 - 1)); }; timer = setTimeout(check, Math.max(0, Math.min(deadline - Date.now(), 2 ** 31 - 1))); return () => clearTimeout(timer); } /** A secret is never normalized: unrepresentable single-line input is refused instead. */ export function isSecretInputValue(value) { return !/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(value); } //# sourceMappingURL=secret-input.js.map