← Public packages
@kentcdodds/sentry-triage
Sentry triage wakes Cole (Grok Bot) per issue: one active wake per repo (lease + queue), loop-safe Discord. Cole may spawn Cursor for isolated repo work.
src/get-issue-state.ts
31 lines · 1.0 KB · TypeScriptimport { packageStorage } from 'kody:runtime'
import {
issueStorageKey,
issuesSeenCounterKey,
maxAgentsPerHour,
spawnedCounterKey,
} from './shared.ts'
import type { GetIssueStateInput, GetIssueStateResult } from './types.ts'
/**
* Loop-guard lookup for triage agents: prior state for one issue plus current
* hourly counters. Invoked cross-package via a static `kody:@kentcdodds/sentry-triage` import.
*/
export default async function getIssueState(
input: GetIssueStateInput,
): Promise<GetIssueStateResult> {
const issueId = String(input.issueId ?? '').trim()
if (!issueId) throw new Error('issueId is required.')
const storage = packageStorage()
const record = (await storage.get(issueStorageKey(issueId))) ?? null
const spawnedThisHour = Number((await storage.get(spawnedCounterKey())) ?? 0)
const issuesSeenThisHour = Number(
(await storage.get(issuesSeenCounterKey())) ?? 0,
)
return {
record,
spawnedThisHour,
issuesSeenThisHour,
capRemaining: Math.max(0, maxAgentsPerHour - spawnedThisHour),
}
}