UNPKG

@code-yeongyu/senpi

Version:

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

62 lines • 2.8 kB
import { isMechanicalContinuationBlock } from "./continuation-recovery.js"; import { readGoal, resetContinuationStreak, updateGoal } from "./store.js"; /** Correlates raw input with admission before changing persisted Goal state. */ export class GoalDirectInputLifecycle { #dependencies; #candidates = new Map(); #suppressedLoadResumeArmed = false; constructor(dependencies) { this.#dependencies = dependencies; } reset() { this.#candidates.clear(); this.#suppressedLoadResumeArmed = false; } /** Arms the one-shot resume for a goal parked by load-time flood suppression. */ armSuppressedLoadResume() { this.#suppressedLoadResumeArmed = true; } async onInput(event, ctx) { if (event.source === "extension") return; this.#dependencies.monitor.holdDirectInput(event.inputId); this.#candidates.set(event.inputId, { goalId: null }); const goal = await readGoal(this.#dependencies.goalStoreRef(ctx)); this.#candidates.set(event.inputId, { goalId: goal?.id ?? null }); } async onDisposition(event, ctx) { const candidate = this.#candidates.get(event.inputId); if (candidate === undefined) return; this.#candidates.delete(event.inputId); const accepted = event.disposition === "started" || event.disposition === "queued"; this.#dependencies.monitor.resolveDirectInput(event.inputId, accepted); if (accepted) this.#dependencies.onAcceptedDirectInput?.(); if (!accepted || candidate.goalId === null) return; const ref = this.#dependencies.goalStoreRef(ctx); const currentGoal = await readGoal(ref); if (currentGoal?.id !== candidate.goalId) return; if (currentGoal.status === "blocked" && isMechanicalContinuationBlock(currentGoal.blockedReason)) { await resetContinuationStreak(ref, { unattended: true }); const reactivated = await updateGoal(ref, { status: "active" }, "user"); this.#dependencies.beginAgentGoalAccounting(reactivated); this.#dependencies.refreshGoalUi(ctx, reactivated); return; } if (currentGoal.status !== "active") return; const reset = await resetContinuationStreak(ref, { unattended: true }); if (reset !== null) { this.#dependencies.beginAgentGoalAccounting(reset); this.#dependencies.refreshGoalUi(ctx, reset); } if (this.#suppressedLoadResumeArmed) { this.#suppressedLoadResumeArmed = false; await this.#dependencies.resumeAfterSuppressedLoad?.(ctx, reset ?? currentGoal); } } } //# sourceMappingURL=direct-input-lifecycle.js.map