UNPKG

@code-yeongyu/senpi

Version:

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

47 lines • 1.58 kB
import { ENGINE_CUSTODY_KEY_PREFIXES } from "../work-obligations.js"; /** An extension asked for a custody key under a prefix only the engine opens (senpi#3986). */ export class ReservedCustodyKey extends Error { constructor(key) { super(`Custody key is reserved for the engine: ${key}`); this.name = "ReservedCustodyKey"; this.key = key; } } function assertExtensionKey(key) { if (ENGINE_CUSTODY_KEY_PREFIXES.some((prefix) => key.startsWith(prefix))) throw new ReservedCustodyKey(key); } function extensionToken(token) { return { transfer(nextKey, kind) { assertExtensionKey(nextKey); return extensionToken(token.transfer(nextKey, kind)); }, ticket: () => token.ticket(), heldAsNotice: (noticeId) => token.heldAsNotice(noticeId), close: (reason) => token.close(reason), }; } function extensionObligations(obligations) { return { open(key, kind, detail) { assertExtensionKey(key); return extensionToken(obligations.open(key, kind, detail)); }, }; } /** Like other extension actions, resolve the live session only when invoked. */ export function createLifecycleApi(resolve) { return { get obligations() { return extensionObligations(resolve().obligations); }, reportChild(report) { resolve().reportChild(report); }, markRunCompleted(run) { resolve().markRunCompleted(run); }, }; } //# sourceMappingURL=lifecycle-api.js.map