@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
53 lines • 2.56 kB
JavaScript
/** Above `ADOPTABLE_MAX` of the private descriptor table (`private-fds.ts`), which forwards 5..15 by number. */
export const STARTUP_EVENT_FD = 16;
export const STARTUP_EVENT_PROTOCOL_VERSION = 1;
export const MAX_STARTUP_EVENT_BYTES = 4096;
/** In the candidate's own generation directory: its attempt nonce and identity, for a later holder's recovery. */
export const STARTUP_ATTEMPT_FILE = "startup-attempt.json";
/**
* In a successor's own generation directory: the launcher's grant to take the public name, for one attempt. The
* supervisor re-reads it inside the endpoint fence right before the adoption rename; the launcher's cleanup removes
* it inside the same fence, so a revoked grant can never be followed by an adoption (senpi#4602 N1).
*/
export const ADOPTION_GRANT_FILE = "adoption-grant.json";
export function encodeStartupHandOff(handOff) {
return JSON.stringify(handOff);
}
export function parseStartupHandOff(value) {
if (!value)
return undefined;
try {
const parsed = JSON.parse(value);
if (typeof parsed !== "object" || parsed === null)
return undefined;
const { binding, role, budgetMs, fillers } = parsed;
if (role !== "supervisor" && role !== "host")
return undefined;
if (typeof budgetMs !== "number" || !Number.isFinite(budgetMs) || budgetMs <= 0)
return undefined;
if (typeof binding !== "object" || binding === null)
return undefined;
const fields = binding;
if (typeof fields.attempt !== "string" || typeof fields.instanceId !== "string")
return undefined;
const slots = Array.isArray(fillers)
? fillers.filter((slot) => Number.isInteger(slot) && slot >= 3 && slot < STARTUP_EVENT_FD)
: [];
return { binding: binding, role, budgetMs, fillers: slots };
}
catch {
return undefined;
}
}
export function startupEventLine(binding, role, seq, milestone) {
return `${JSON.stringify({ v: STARTUP_EVENT_PROTOCOL_VERSION, binding, role, seq, milestone })}\n`;
}
/** The launcher's wake-up to a successor supervisor on the same pipe, in the other direction: P7 resolved. */
export function startupGrantLine(attempt) {
return `${JSON.stringify({ grant: "public_published", attempt })}\n`;
}
/** The supervisor's frame around one host-child record line (without its LF). */
export function relayStartupLine(line) {
return `${JSON.stringify({ relay: "host", line })}\n`;
}
//# sourceMappingURL=host-startup-wire.js.map