UNPKG

@code-yeongyu/senpi

Version:

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

36 lines • 1.94 kB
import { AsyncLocalStorage } from "node:async_hooks"; import { hasFunctions, realmRegistry } from "@earendil-works/pi-realm-registry"; const isAsyncContext = (value) => hasFunctions(value, ["run", "exit", "getStore"]); const kernelToolContexts = realmRegistry("@code-yeongyu/senpi/kernel-tools/v1", () => ({ storage: new AsyncLocalStorage(), invokerStorage: new AsyncLocalStorage(), }), (value) => typeof value === "object" && value !== null && isAsyncContext(Reflect.get(value, "storage")) && isAsyncContext(Reflect.get(value, "invokerStorage"))); export const kernelToolsStorage = kernelToolContexts.storage; /** The active host dispatcher, including when it executes a capability captured in another session. */ export const kernelToolInvokerStorage = kernelToolContexts.invokerStorage; function isKernelTools(value) { if (typeof value !== "object" || value === null) return false; const capabilities = Reflect.get(value, "capabilities"); return (typeof capabilities === "object" && capabilities !== null && typeof Reflect.get(capabilities, "invokeScope") === "boolean" && hasFunctions(value, ["describe", "invoke"])); } function isKernelToolInvoker(value) { return typeof value === "object" && value !== null && typeof Reflect.get(value, "sessionId") === "string"; } /** The kernel tools entered for this async context by any engine copy; a store missing its members reads as absent. */ export function activeKernelTools() { const tools = kernelToolsStorage.getStore(); return isKernelTools(tools) ? tools : undefined; } /** The host dispatcher identity entered for this async context by any engine copy; an ill-typed one reads as absent. */ export function activeKernelToolInvoker() { const invoker = kernelToolInvokerStorage.getStore(); return isKernelToolInvoker(invoker) ? invoker : undefined; } //# sourceMappingURL=kernel-tools-context.js.map