UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 2.56 kB
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { i as SESSION_PROCESS_TAIL_MAX_CHARS, n as SESSION_PROCESSES_MAX_ROWS, r as SESSION_PROCESS_NAME_MAX_CHARS, t as SESSION_PROCESSES_MAX_BYTES } from "./session-processes-DebzuCNx.mjs"; import { E as tail, N as deriveSessionName, a as compareProcessSessionStartOrder, h as listRunningSessions, m as listFinishedSessions, u as getSession, x as processSessionInstanceId } from "./bash-process-registry-Dh1460VO.mjs"; import { a as isConfirmedRequestedStop, i as isBackgroundExecCancellable, t as cancelBackgroundExecSession } from "./bash-process-control-aLfvOIsE.mjs"; //#region src/agents/bash-process-observation.ts function inScope(e, t) { return Boolean(e.scopeKey && t.scopeKeys.includes(e.scopeKey) && (e.agentId === void 0 || e.agentId === t.agentId) && (e.scopeKey !== "global" || e.agentId === t.agentId)); } /** Non-consuming observation: never drains poll output or acknowledges an exit notification. */ function readBackgroundProcesses(e) { const t = [...listRunningSessions(), ...listFinishedSessions()].filter((t) => inScope(t, e)).toSorted((e, t) => Number(e.exited) - Number(t.exited) || compareProcessSessionStartOrder(e, t)); const n = []; let r = 0; for (const e of t) { const t = tail(e.tail, SESSION_PROCESS_TAIL_MAX_CHARS); const i = { processId: e.id, instanceId: processSessionInstanceId(e), name: truncateUtf16Safe(deriveSessionName(e.command) || e.command, 160), status: isConfirmedRequestedStop(e) ? "killed" : e.terminalStatus ?? "running", startedAt: e.startedAt, ...e.endedAt !== void 0 ? { endedAt: e.endedAt } : {}, tail: t, truncated: e.truncated || e.totalOutputChars > t.length, canStop: isBackgroundExecCancellable(e) && !e.cancellationRequested, ...e.exitCode !== void 0 ? { exitCode: e.exitCode } : {}, ...e.exitSignal !== void 0 ? { exitSignal: e.exitSignal } : {}, ...e.exitReason !== void 0 ? { exitReason: e.exitReason } : {} }; r += Buffer.byteLength(JSON.stringify(i), "utf8"); if (n.length >= 50 || r > 49152) break; n.push(i); } return { processes: n, truncated: n.length < t.length }; } /** The session authority is checked by the caller; this owner checks the exact process object. */ function stopBackgroundProcess(e, t) { const n = getSession(t.processId); return { requested: Boolean(n && inScope(n, e) && processSessionInstanceId(n) === t.instanceId && cancelBackgroundExecSession(n.id)) }; } //#endregion export { stopBackgroundProcess as n, readBackgroundProcesses as t };