@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
22 lines • 1.43 kB
JavaScript
/** An assistant without a persisted entry is judged as projected, like the upstream session core. */
export function resolveAssistantUsageScope(branch, buildProjection, assistantEntryId) {
if (assistantEntryId === undefined) {
return { projected: true, usageMatchesProjection: true, retainedForExplicitRecovery: true };
}
const assistantIndex = branch.findIndex((entry) => entry.id === assistantEntryId);
const later = assistantIndex >= 0 ? branch.slice(assistantIndex + 1) : [];
if (assistantIndex >= 0 && !later.some((entry) => entry.type === "context_edit" || entry.type === "compaction")) {
return { projected: true, usageMatchesProjection: true, retainedForExplicitRecovery: true };
}
const projected = buildProjection().entries.some((entry) => entry.sourceEntry.id === assistantEntryId && entry.messages.some((message) => message.role === "assistant"));
const latestEdit = later
.filter((entry) => entry.type === "context_edit" && entry.targetId === assistantEntryId)
.at(-1);
const omitted = latestEdit?.type === "context_edit" && latestEdit.replacement === null;
return {
projected,
usageMatchesProjection: projected && !later.some((entry) => entry.type === "context_edit"),
retainedForExplicitRecovery: !omitted && !later.some((entry) => entry.type === "compaction"),
};
}
//# sourceMappingURL=assistant-usage-scope.js.map