@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
27 lines • 1.49 kB
JavaScript
import { AsyncLocalStorage } from "node:async_hooks";
import { compactUpdatesEnabled } from "../../core/engine-socket-flag.js";
const requests = new AsyncLocalStorage();
/** Bounded reply identity, not the command body or a retained request index, crosses an isolate. */
export function captureAdmissionReply() {
const scope = requests.getStore();
return scope && { id: scope.command.id, admissionId: scope.command.admissionId, peer: scope.peer };
}
export function withAdmissionReply(scope, action) {
return scope === undefined ? action() : requests.run({ command: scope, peer: scope.peer }, action);
}
/** Request scope, not a retained request index: async session replies keep their caller's route. */
export function withAdmissionRequest(command, peer, action) {
if (!compactUpdatesEnabled())
return action();
return requests.run({ command, peer }, action);
}
export function replyAdmission(id, peer, routes) {
const request = requests.getStore();
// No matching request scope means ownership cannot be proved. Drop (null), never guess routes[0];
// undefined is reserved for a matching legacy request that did not select an admission.
if (!request || request.command.id !== id || request.peer !== peer)
return null;
const admissionId = request.command.admissionId;
return admissionId === undefined ? undefined : (routes.find((route) => route === admissionId) ?? null);
}
//# sourceMappingURL=compact-admission-reply.js.map