@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
34 lines • 1.69 kB
JavaScript
import { AssistantEditError, assertExpectedLeaf } from "../../core/edited-assistant-message.js";
import { lifecycleEditLeaf } from "../../core/lifecycle-edit-leaf.js";
import { RPC_ERROR_INVALID_ARGUMENT, RPC_ERROR_STALE_LEAF } from "./rpc-types.js";
/**
* senpi#6922: a prompt naming the leaf it was decided at is refused before admission when the session moved.
* Lifecycle bookkeeping after that leaf is not a move (the same rule as the edit commands). A queued delivery runs
* later, at a leaf this admission-time check never sees, so it cannot carry the guard; neither can a prompt a live hold
* would keep as a notice, which a later turn consumes at another leaf.
*/
export function refusePromptAtMovedLeaf(session, command, heldAsNotice) {
const { expectedLeafId } = command;
if (expectedLeafId === undefined)
return undefined;
if (command.streamingBehavior !== undefined)
return {
message: "expectedLeafId cannot be combined with streamingBehavior: a queued prompt runs at a later leaf.",
errorCode: RPC_ERROR_INVALID_ARGUMENT,
};
if (heldAsNotice)
return {
message: "expectedLeafId cannot be honoured while a Stop or run hold keeps input as a notice for a later turn.",
errorCode: RPC_ERROR_INVALID_ARGUMENT,
};
try {
assertExpectedLeaf(expectedLeafId, lifecycleEditLeaf(session.sessionManager, expectedLeafId));
return undefined;
}
catch (err) {
if (err instanceof AssistantEditError)
return { message: err.message, errorCode: RPC_ERROR_STALE_LEAF };
throw err;
}
}
//# sourceMappingURL=prompt-expected-leaf.js.map