@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
34 lines • 1.64 kB
JavaScript
import { createAdmissionLine, createWakeOutbox, } from "@earendil-works/pi-agent-core";
import { claimStateStore, openStateFileStore } from "../rpc/state-file-store.js";
/**
* How many un-acked wakes a hand keeps while its brain is away (senpi#6767 review M1): per scope, as the loop-hook hold
* it replaces kept per session, and in total across the hand's scopes. Past a bound a wake the brain refused for good is
* evicted (reported `refused`), or else the new wake is refused before it is sent (reported `overflow`); a wake already
* sent is never evicted.
*/
const HAND_WAKE_LIMITS = { perScope: 256, total: 1024 };
/**
* The hand's wake outbox on its state file: this process claims the file's next owner epoch, so a hand that opened it
* earlier is refused from then on. Every event id it mints starts with `hand:`.
*/
export async function openHandWakeOutbox(path, options = {}) {
const store = openStateFileStore(path);
const epoch = await claimStateStore(store);
return createWakeOutbox({
hand: "hand",
store,
epoch,
admission: createAdmissionLine(),
clock: options.clock ?? Date.now,
limits: options.limits ?? HAND_WAKE_LIMITS,
...(options.onFault === undefined ? {} : { onFault: options.onFault }),
});
}
/** A hand's scopes' wakes over its wake link; the link reports every failure itself, so nothing here throws. */
export function handWakesOver(link) {
return {
offer: (scope, wake) => void link.offer({ scope, ...wake }),
closeScope: (scope) => void link.closeScope(scope),
};
}
//# sourceMappingURL=hand-wakes.js.map