UNPKG

@code-yeongyu/senpi

Version:

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

47 lines • 1.91 kB
export const JOB_WIDGET_REQUEST_LIMITS = { authorAfterMs: 15_000, minLines: 3, maxRequestsPerJob: 3, maxInFlight: 2, maxPerHour: 30, driftLines: 200, driftStaleMs: 90_000, noModelRetryMs: 30_000, }; export const REQUEST_WINDOW_MS = 60 * 60 * 1000; export function newAuthoringState() { return { requests: 0, inFlight: false, stopped: false, specHadWatch: false }; } function reauthorReason(job, state, now, limits) { const { brief, runtime } = job; if (brief.watch && !state.specHadWatch) return `the subagent now says what to watch: ${brief.watch}`; if (runtime.unmatchedLines < limits.driftLines) return undefined; const newest = runtime.lastMatchAt; if (newest !== undefined && now - newest <= limits.driftStaleMs) return undefined; return `no rule matched the last ${runtime.unmatchedLines} lines`; } /** * The request a job is due, or `undefined`. A task job waits for its `watch` hint: most subagents * read and edit code, and only the subagent knows whether some output shows progress. */ export function planRequest(job, state, now, limits) { if (state.inFlight || state.stopped || state.requests >= limits.maxRequestsPerJob) return undefined; if (now - job.startTime < limits.authorAfterMs) return undefined; const { brief, runtime } = job; if (brief.kind === "task" && !brief.watch) return undefined; const skipped = state.skippedWatch; if (skipped !== undefined && (brief.kind === "bash" || skipped === brief.watch)) return undefined; if (runtime.spec) { const reason = reauthorReason(job, state, now, limits); return reason ? { previous: { spec: runtime.spec, reason } } : undefined; } return runtime.samples().some((sample) => sample.lines >= limits.minLines) ? {} : undefined; } //# sourceMappingURL=request-policy.js.map