@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
71 lines • 2.92 kB
JavaScript
export class SessionRunActivity {
/** Settled sessions not yet at agent_idle, by settle time (omo#11419). */
constructor(options = {}) {
this.
this.
this.
}
/** Applies one host event line; true when it is a run or session event the idle decision must re-read. */
observe(line) {
const event = parseHostEvent(line);
if (event === undefined)
return false;
if (event.type === "agent_start") {
this.
this.
}
else if (event.type === "agent_settled" && event.reason !== "session_closed") {
// The run is over, but agent_settled reaches clients before its extension handlers finish (omo#11419): the
// session holds idle exit until agent_idle, for at most the settle hold.
this.
this.
}
else if (event.type === "agent_settled" || event.type === "agent_idle" || event.type === "session_closed") {
// A seal's owed settle (reason session_closed) or a closed session: nothing is left to wait for.
this.
this.
}
else
return false;
return true;
}
/** Sessions with a run in progress. */
get busySessions() {
return this.
}
/** Settled sessions whose agent_settled handlers may still run, within the settle hold. */
get settlingSessions() {
const now = this.
for (const [sessionId, settledAt] of this.
const heldMs = now - settledAt;
if (heldMs < this.
continue;
this.
this.
}
return this.
}
}
/** An idle window that ran out still waits while a settled session's handlers are within their hold (omo#11419). */
export function holdIdleExitForSettling(decision, runs) {
return decision === "exit" && runs.settlingSessions > 0 ? "idle" : decision;
}
function parseHostEvent(line) {
let event;
try {
event = JSON.parse(line);
}
catch {
return undefined;
}
if (typeof event !== "object" || event === null)
return undefined;
const { type, sessionId, reason } = event;
return typeof sessionId === "string" ? { type, sessionId, reason } : undefined;
}
//# sourceMappingURL=host-run-activity.js.map