






















@@ -334,14 +334,6 @@ export function readClaudeCliSessionMessages(params: {
334334return coalesceClaudeCliToolMessages(messages);
335335}
336336337-// Compaction surface in Claude Code's JSONL: `/compact` writes a
338-// `type: "summary"` entry whose `summary` field holds the condensed text,
339-// and an associated `type: "system", subtype: "compact_boundary"` entry
340-// whose `compactMetadata` carries `trigger`/`preTokens`. After a boundary,
341-// only post-compaction `user`/`assistant` turns are written as individual
342-// entries; pre-compaction context lives in the summary. This shape mirrors
343-// what Claude Code itself sends to the model after compaction (summary plus
344-// recent turns), per the upstream session-management docs.
345337type ClaudeCliCompactBoundaryEntry = {
346338type: "system";
347339subtype?: unknown;
@@ -361,20 +353,7 @@ type ClaudeCliSummaryEntry = {
361353};
362354363355export type ClaudeCliFallbackSeed = {
364-/**
365- * The most recent compaction summary, if the session has been `/compact`-ed
366- * at any point. Sourced from the latest `type: "summary"` entry, falling
367- * back to the latest `compact_boundary` content when no explicit summary
368- * is present (older Claude Code builds).
369- */
370356summaryText?: string;
371-/**
372- * User/assistant turns after the most recent compact boundary, or all
373- * turns when the session has never been compacted. Tool-result turns are
374- * coalesced into adjacent assistant turns the same way
375- * `readClaudeCliSessionMessages` does, so consumers can format them like
376- * a regular transcript.
377- */
378357recentTurns: TranscriptLikeMessage[];
379358};
380359@@ -387,11 +366,6 @@ function isCompactBoundary(entry: ClaudeCliProjectEntry): boolean {
387366}
388367389368function extractCompactBoundaryFallbackText(entry: ClaudeCliProjectEntry): string | undefined {
390-// When `/compact` is invoked, Claude Code writes a separate summary entry
391-// — but on older builds the boundary's `content` ("Conversation compacted")
392-// is the only signal that compaction happened. Prefer the explicit summary
393-// when both exist; this fallback gives a non-empty hint when only the
394-// boundary is present so the seed at least labels the gap honestly.
395369const content = (entry as ClaudeCliCompactBoundaryEntry).content;
396370return typeof content === "string" && content.trim() ? content.trim() : undefined;
397371}
@@ -420,17 +394,6 @@ export function readClaudeCliFallbackSeed(params: {
420394return undefined;
421395}
422396423-// Pair each compact_boundary with the summary entry that preceded it
424-// since the previous boundary, so a later compaction whose summary is
425-// missing (e.g. crash mid-write) does not silently keep an older
426-// compaction's summary alive (#72069 Codex P2). Walk shape:
427-// - explicit `summary` entry queues into `pendingSummary` until the
428-// next boundary "consumes" it.
429-// - `compact_boundary` flushes the pending summary into `lastSummary`,
430-// refreshes `lastBoundaryFallback` from the boundary's content, and
431-// drops the windowed turns and tool registry.
432-// - everything after the latest boundary forms the recent-window the
433-// fallback runner will replay alongside the summary.
434397let pendingSummary: string | undefined;
435398let lastSummary: string | undefined;
436399let lastBoundaryFallback: string | undefined;
@@ -450,23 +413,15 @@ export function readClaudeCliFallbackSeed(params: {
450413451414const explicitSummary = extractSummaryText(parsed);
452415if (explicitSummary) {
453-// Queue the summary; the next boundary will pair it with itself.
454-// Multiple summaries between boundaries (rare) take the last one,
455-// matching how Claude Code's resume picks the most recent summary.
456416pendingSummary = explicitSummary;
457417continue;
458418}
459419460420if (isCompactBoundary(parsed)) {
461-lastSummary = pendingSummary; // may be undefined if no preceding summary
421+lastSummary = pendingSummary;
462422pendingSummary = undefined;
463423lastBoundaryFallback = extractCompactBoundaryFallbackText(parsed) ?? lastBoundaryFallback;
464-// Drop turns that lived before this boundary — they are now
465-// represented by the summary, and replaying them would double-count
466-// their tokens against the fallback model's budget.
467424windowedTurns = [];
468-// Reset tool-name registry too: tool ids before a compact boundary
469-// are no longer visible to the post-boundary turns.
470425toolNameRegistry.clear();
471426continue;
472427}
@@ -478,9 +433,6 @@ export function readClaudeCliFallbackSeed(params: {
478433}
479434480435const recentTurns = coalesceClaudeCliToolMessages(windowedTurns);
481-// Honor a `/compact` summary that was written but never followed by a
482-// boundary marker (older Claude Code build, or graceful-degrade case).
483-// `pendingSummary` then carries the latest such summary into the result.
484436const resolvedSummaryText = lastSummary ?? pendingSummary ?? lastBoundaryFallback;
485437if (!resolvedSummaryText && recentTurns.length === 0) {
486438return undefined;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。