UNPKG

@code-yeongyu/senpi

Version:

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

26 lines • 1.14 kB
import { toStoreValue } from "@earendil-works/pi-agent-core"; export class LifecycleRefusedError extends Error { constructor(kind, reason) { super(`lifecycle event ${kind} refused: ${reason}`); this.name = "LifecycleRefusedError"; this.reason = reason; } } /** * One session's lifecycle on a split endpoint (design 5.6.6): an extension lifecycle handler (`agent_end`, * `turn_start`, ...) runs through the scope so its effect commits before the event is admitted, and every tool call * goes through `call`, so a call issued after the event runs only after that commit. */ export function createLifecycleBridge(options) { const { scopes, issuer, scope } = options; return { event: async (kind, handler) => { const admitted = await scopes.lifecycle(issuer, scope, kind, async () => toStoreValue((await handler()) ?? null)); if (admitted.kind === "refused") throw new LifecycleRefusedError(kind, admitted.reason); return admitted.seq; }, call: (run) => scopes.call(scope, run), }; } //# sourceMappingURL=lifecycle.js.map