UNPKG

@code-yeongyu/senpi

Version:

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

37 lines • 2.44 kB
export const BASH_DEFAULT_TIMEOUT_SECONDS = 1800; export const BASH_MAX_TIMEOUT_SECONDS = 1800; function parsePositiveInt(value) { if (!value) return undefined; const parsed = Number.parseInt(value, 10); if (!Number.isFinite(parsed) || parsed <= 0) return undefined; return parsed; } export function resolveBashTimeoutDefaults(env) { const { PI_BASH_DEFAULT_TIMEOUT_SECONDS: defaultTimeout, PI_BASH_MAX_TIMEOUT_SECONDS: maxTimeout } = env; const defaultSeconds = parsePositiveInt(defaultTimeout) ?? BASH_DEFAULT_TIMEOUT_SECONDS; const rawMax = parsePositiveInt(maxTimeout) ?? BASH_MAX_TIMEOUT_SECONDS; const maxSeconds = Math.max(rawMax, defaultSeconds); return { defaultSeconds, maxSeconds }; } export function applyBashTimeout(input, defaults) { const current = input.timeout; if (current === undefined || current <= 0) { return { ...input, timeout: defaults.defaultSeconds }; } return input; } /** The pre-diet timeout policy section; only presets that render full shared sections append it (senpi#5665). */ export function buildBashTimeoutPrompt(defaults, options = {}) { const { foregroundWindowSeconds, evalOnly = false } = options; const subject = evalOnly ? "Shell commands run from an eval cell as `tool.bash({ command, timeout })`; its `timeout` parameter" : "The `bash` tool's `timeout` parameter"; const minutes = (seconds) => (seconds % 60 === 0 ? `${seconds / 60} min` : `${seconds}s`); const detachRules = foregroundWindowSeconds === undefined ? "" : `\n- Foreground blocking stops at the ~${foregroundWindowSeconds}s window. A command still running then auto-detaches alive to a background session with a \`bash_id\` and keeps running until it exits or hits the kill deadline; the session tools in the terminal section steer or stop it.`; return `\n## Bash Tool Timeout Policy\n\n${subject} is the process kill deadline, not how long you wait for output: the command is killed when it reaches the deadline.\n\n- Default timeout: ${defaults.defaultSeconds}s (${minutes(defaults.defaultSeconds)}). Applied automatically when you do not set \`timeout\`.\n- Recommended maximum timeout: ${defaults.maxSeconds}s (${minutes(defaults.maxSeconds)}). Explicit \`timeout\` values are preserved because different hosts may use different timeout units.${detachRules}`; } //# sourceMappingURL=timeout.js.map