@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
67 lines • 3.04 kB
JavaScript
/**
* The vocabulary every `senpi host` answer is written in: the exit codes, the identity fields of a
* host, and the two ways a request ends without acting. Shared by the request runner and the
* conditional idle handover, so both report one host the same way.
*/
import { engineBuildIdentity } from "../../core/engine-build-identity.js";
import { decideHostAction, HOST_PROTOCOL_VERSION, REQUIRED_HOST_CAPABILITIES, } from "./host-decision.js";
import { hostSummary } from "./host-status.js";
import { socketHostLaunchProfile } from "./protocol-identity.js";
import { computeRuntimeBuildId } from "./runtime-build-id.js";
export const HOST_EXIT_OK = 0;
export const HOST_EXIT_ERROR = 1;
export const HOST_EXIT_USAGE = 2;
export const HOST_EXIT_REFUSED = 3;
export const HOST_EXIT_FALLBACK = 4;
export function identityPayload(socket, pid, host) {
return {
socket,
pid,
lifecycle: host?.lifecycle ?? null,
instanceId: host?.instanceId ?? null,
generation: host?.generation ?? null,
engineVersion: host?.engineVersion ?? null,
engineOrdinal: host?.engineOrdinal ?? null,
capabilities: host?.capabilities ?? [],
launchProfileId: host?.launch_profile?.profile_id ?? null,
runtimeBuildId: host?.runtimeBuildId ?? null,
upgradeable: decideHostAction(decisionClient(), host, "upgrade").upgradeable,
};
}
/**
* The `runtimeBuildId` a host launched from `spec` by THIS process would report: this process's
* runtime plus the spec's extensions, through the same launch profile the host derives from its
* argv. A runtime that cannot be read reports `null` (unverified) rather than failing the request.
*/
export async function clientRuntimeBuildId(spec) {
const profile = socketHostLaunchProfile(spec.hostArgs, process.cwd());
return computeRuntimeBuildId({ profile: profile.core }).catch((cause) => {
process.stderr.write(`senpi host: runtime identity unreadable: ${String(cause)}\n`);
return null;
});
}
/**
* The two ways a request ends without acting, and the exit codes they mean: a `refuse` leaves a
* running host alone (3), a `fallback` says no host is better than this one (4).
*/
export function refusal(kind, host, body) {
return {
exitCode: kind === "refuse" ? HOST_EXIT_REFUSED : HOST_EXIT_FALLBACK,
payload: { action: kind, ...body, host: hostSummary(host) },
};
}
/**
* This build as a client, WITHOUT a launch profile: the request's own `ensureHost` decides whether a
* handoff may happen, from the profile it would launch. What is asked here is only what any client
* can answer without one - is the running host usable, and could it be handed off from at all.
*/
export function decisionClient() {
return {
protocolVersion: HOST_PROTOCOL_VERSION,
requiredCapabilities: REQUIRED_HOST_CAPABILITIES,
identity: engineBuildIdentity(),
startedByUs: false,
platform: process.platform,
};
}
//# sourceMappingURL=host-outcome.js.map