Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/harness/src/context/build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ function text(value: unknown, fallback = "") {
return typeof value === "string" ? value : fallback;
}

/**
* Durable handoff text for resume. New completed entries carry validated
* rendered markdown; older entries already stored prose in the same field.
* Neither form requires reading any filesystem location.
*/
function resumeHandoffText(entry: SessionEntry): string | null {
const handoff = entry.payload.handoff;
if (typeof handoff === "string" && handoff.trim()) return handoff;
return null;
}

export function buildModelContext(entries: SessionEntry[]): ModelContextItem[] {
const context: ModelContextItem[] = [];
const compaction = latestCompletedCompaction(entries);
const visibleEntries = compaction ? entries.slice(compaction.index + 1) : entries;
const completed = latestCompletedCompaction(entries);
const handoff = completed ? resumeHandoffText(completed.entry) : null;
// A corrupt/missing summary cannot authorize dropping any earlier context.
const compaction = handoff === null ? null : completed;
const visibleEntries = (compaction ? entries.slice(compaction.index + 1) : entries).filter(
(entry) => entry.payload.purpose !== "compaction",
);
const responsesByRun = new Map<
string,
import("../models/transport.ts").ProviderResponseMetadata
Expand All @@ -24,10 +40,10 @@ export function buildModelContext(entries: SessionEntry[]): ModelContextItem[] {
);
}
}
if (compaction) {
if (compaction && handoff !== null) {
context.push({
type: "user_message",
text: buildResumePrompt(text(compaction.entry.payload.handoffDirectory)),
text: buildResumePrompt(handoff),
model: compaction.entry.payload.model as { connectionId: string; modelId: string },
reasoning: text(compaction.entry.payload.reasoning, "none"),
});
Expand Down
Loading
Loading