pi-fabric 0.93.0 → 0.93.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/handoff.d.ts +2 -1
- package/dist/agents/handoff.d.ts.map +1 -1
- package/dist/agents/manager.d.ts +2 -0
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents.js +2 -2
- package/dist/chunks/{chunk-2SWRVIYJ.js → chunk-2X3363IK.js} +2 -2
- package/dist/chunks/{chunk-MQG5QKGI.js → chunk-SRZPJBNP.js} +187 -92
- package/dist/chunks/chunk-SRZPJBNP.js.map +7 -0
- package/dist/chunks/{chunk-Q4XJ4PYL.js → chunk-SUJ5KLCS.js} +25 -21
- package/dist/chunks/chunk-SUJ5KLCS.js.map +7 -0
- package/dist/chunks/{chunk-3H7SDWZI.js → chunk-UQ7GWC27.js} +13 -1
- package/dist/chunks/chunk-UQ7GWC27.js.map +7 -0
- package/dist/chunks/{chunk-K6DHXXF5.js → chunk-YDZOEKI6.js} +2 -2
- package/dist/compaction/bounds.d.ts +4 -0
- package/dist/compaction/bounds.d.ts.map +1 -1
- package/dist/compaction/branch-summary.d.ts.map +1 -1
- package/dist/compaction/dialogue.d.ts +24 -0
- package/dist/compaction/dialogue.d.ts.map +1 -0
- package/dist/compaction/hook.d.ts +4 -2
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +2 -2
- package/dist/compaction/instructions.d.ts +1 -0
- package/dist/compaction/instructions.d.ts.map +1 -1
- package/dist/compaction/projections.d.ts +3 -3
- package/dist/compaction/projections.d.ts.map +1 -1
- package/dist/compaction/qa.d.ts.map +1 -1
- package/dist/compaction/render.d.ts +11 -0
- package/dist/compaction/render.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +17 -4
- package/dist/fabric-runtime-state.js.map +2 -2
- package/dist/index.js +2 -2
- package/dist/residency/host.js +4 -4
- package/dist/residency/pi-entry.js +4 -4
- package/docs/agents.md +1 -1
- package/docs/compaction.md +91 -28
- package/docs/programmatic-compaction.md +11 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-3H7SDWZI.js.map +0 -7
- package/dist/chunks/chunk-MQG5QKGI.js.map +0 -7
- package/dist/chunks/chunk-Q4XJ4PYL.js.map +0 -7
- /package/dist/chunks/{chunk-2SWRVIYJ.js.map → chunk-2X3363IK.js.map} +0 -0
- /package/dist/chunks/{chunk-K6DHXXF5.js.map → chunk-YDZOEKI6.js.map} +0 -0
package/dist/agents/handoff.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type FabricCompactionBudget } from "../compaction/hook.js";
|
|
2
3
|
import type { AgentSessionSeed, AgentToolResultMessage, HandoffCompactionRequest } from "./types.js";
|
|
3
4
|
import { type ThinkingTransferInput } from "./thinking-transfer.js";
|
|
4
5
|
interface HandoffSessionSource {
|
|
@@ -14,6 +15,6 @@ interface CurrentModel {
|
|
|
14
15
|
}
|
|
15
16
|
export declare const checkedHandoffCompaction: (value: unknown) => HandoffCompactionRequest | undefined;
|
|
16
17
|
export declare const snapshotHandoffSession: (source: HandoffSessionSource, currentModel: CurrentModel | undefined, outerToolResult: AgentToolResultMessage, outerToolCallId: string) => AgentSessionSeed;
|
|
17
|
-
export declare const writeHandoffSession: (seed: AgentSessionSeed, cwd: string, directory: string, transfer?: ThinkingTransferInput, compaction?: HandoffCompactionRequest) => string;
|
|
18
|
+
export declare const writeHandoffSession: (seed: AgentSessionSeed, cwd: string, directory: string, transfer?: ThinkingTransferInput, compaction?: HandoffCompactionRequest, compactionBudget?: FabricCompactionBudget) => string;
|
|
18
19
|
export {};
|
|
19
20
|
//# sourceMappingURL=handoff.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../../src/agents/handoff.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../../src/agents/handoff.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAA0C,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAK5G,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAKL,KAAK,qBAAqB,EAE3B,MAAM,wBAAwB,CAAC;AAEhC,UAAU,oBAAoB;IAC5B,SAAS,IAAI,YAAY,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAC/C,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,IAAI,MAAM,GAAG,SAAS,CAAC;IACrC,YAAY,IAAI,MAAM,CAAC;CACxB;AAED,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ;AAuBD,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,wBAAwB,GAAG,SA4B7B,CAAC;AAwCF,eAAO,MAAM,sBAAsB,GACjC,QAAQ,oBAAoB,EAC5B,cAAc,YAAY,GAAG,SAAS,EACtC,iBAAiB,sBAAsB,EACvC,iBAAiB,MAAM,KACtB,gBAiCF,CAAC;AAqFF,eAAO,MAAM,mBAAmB,GAC9B,MAAM,gBAAgB,EACtB,KAAK,MAAM,EACX,WAAW,MAAM,EACjB,WAAW,qBAAqB,EAChC,aAAa,wBAAwB,EACrC,mBAAmB,sBAAsB,KACxC,MAsFF,CAAC"}
|
package/dist/agents/manager.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type FabricAgentRunner, type FabricAgentConfig, type FabricRetentionCon
|
|
|
3
3
|
import { type ClaudeModelInfo } from "./claude-cli.js";
|
|
4
4
|
import { type InheritedSessionPin } from "./session-pins.js";
|
|
5
5
|
import type { FabricSteeringMode, FabricAgentLog, AgentHandleInfo, AgentRunRecord, AgentRunRequest, AgentRunResult, AgentSteerResult } from "./types.js";
|
|
6
|
+
import type { FabricCompactionBudget } from "../compaction/hook.js";
|
|
6
7
|
import { type FabricLifecyclePublishRequest } from "../lifecycle/types.js";
|
|
7
8
|
export declare const effectiveAgentTimeoutMs: (configuredTimeoutMs: number, requestedTimeoutMs?: number) => number;
|
|
8
9
|
interface AgentParticipantGuidanceRequest {
|
|
@@ -37,6 +38,7 @@ export declare class AgentManager {
|
|
|
37
38
|
onResultConsumed?: (id: string) => void;
|
|
38
39
|
onLifecycle?: (event: FabricLifecyclePublishRequest) => void;
|
|
39
40
|
preparePiModel?: (model: string | undefined) => Promise<string | void>;
|
|
41
|
+
resolveHandoffCompactionBudget?: (model: string | undefined, cwd: string) => Promise<FabricCompactionBudget>;
|
|
40
42
|
resolveParticipantGuidance?: AgentParticipantGuidanceResolver;
|
|
41
43
|
resolveInheritedSessionPins?: () => InheritedSessionPin[] | undefined;
|
|
42
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/agents/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOzD,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEtB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAU3B,OAAO,KAAK,EAEV,kBAAkB,EAClB,cAAc,EACd,eAAe,EAEf,cAAc,EACd,eAAe,EACf,cAAc,EAEd,gBAAgB,E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AAE,MAAM,CAAA;KAAO,GAAG,cAAc;IAkBnF,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,gBAAgB;IAKpE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,gBAAgB;IAgBvE,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,gBAAgB;IAIvE,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,gBAAgB;IAUvE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,gBAAgB;IA4B5D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAorBvB"}
|
package/dist/agents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AGENTS_ACTION_DESCRIPTORS,
|
|
3
3
|
normalizeAgentRunRequest
|
|
4
|
-
} from "./chunks/chunk-
|
|
4
|
+
} from "./chunks/chunk-2X3363IK.js";
|
|
5
5
|
import {
|
|
6
6
|
validateAgentResult
|
|
7
7
|
} from "./chunks/chunk-3QECYQGA.js";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import "./chunks/chunk-2QAOC3BO.js";
|
|
21
21
|
import "./chunks/chunk-A4VP7HDF.js";
|
|
22
22
|
import "./chunks/chunk-MGWQOKBV.js";
|
|
23
|
-
import "./chunks/chunk-
|
|
23
|
+
import "./chunks/chunk-UQ7GWC27.js";
|
|
24
24
|
|
|
25
25
|
// src/agents/service-schema.ts
|
|
26
26
|
import { Value } from "typebox/value";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
MAX_COMPACTION_INSTRUCTIONS_CHARS,
|
|
15
15
|
MAX_PRESERVE_ITEMS,
|
|
16
16
|
MAX_PRESERVE_ITEM_CHARS
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-UQ7GWC27.js";
|
|
18
18
|
|
|
19
19
|
// src/providers/agents-actions.ts
|
|
20
20
|
var runProperties = {
|
|
@@ -747,4 +747,4 @@ export {
|
|
|
747
747
|
AGENTS_ACTION_DESCRIPTORS,
|
|
748
748
|
normalizeAgentRunRequest
|
|
749
749
|
};
|
|
750
|
-
//# sourceMappingURL=chunk-
|
|
750
|
+
//# sourceMappingURL=chunk-2X3363IK.js.map
|
|
@@ -13,13 +13,14 @@ import {
|
|
|
13
13
|
} from "./chunk-ZDNGXLEC.js";
|
|
14
14
|
import {
|
|
15
15
|
MAX_SUMMARY_BYTES,
|
|
16
|
+
boundedExcerpt,
|
|
16
17
|
clipUtf8,
|
|
17
18
|
decodeCompactionInstructions,
|
|
18
19
|
omissionLine,
|
|
19
20
|
sampleAddressed,
|
|
20
21
|
sampleAddressedFrom,
|
|
21
22
|
utf8Bytes
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-UQ7GWC27.js";
|
|
23
24
|
|
|
24
25
|
// src/compaction/hook.ts
|
|
25
26
|
import "@earendil-works/pi-coding-agent";
|
|
@@ -615,12 +616,67 @@ var countErasedThinkingBlocks = (entries) => {
|
|
|
615
616
|
return count;
|
|
616
617
|
};
|
|
617
618
|
|
|
619
|
+
// src/compaction/dialogue.ts
|
|
620
|
+
var MAX_RECENT_EXCHANGES = 3;
|
|
621
|
+
var MAX_EXCHANGE_BYTES = 3968;
|
|
622
|
+
var recentDialogue = (events, retainedTail = []) => {
|
|
623
|
+
const exchanges = [];
|
|
624
|
+
let assistant;
|
|
625
|
+
const visit = (source, retained) => {
|
|
626
|
+
for (const event of source) {
|
|
627
|
+
if (event.kind === "assistantText" && event.text.trim()) {
|
|
628
|
+
if (assistant?.entryId === event.entryId) assistant.text += `
|
|
629
|
+
${event.text}`;
|
|
630
|
+
else assistant = { entryId: event.entryId, text: event.text, retained };
|
|
631
|
+
} else if (event.kind === "user") {
|
|
632
|
+
if (!retained || assistant?.retained === false) {
|
|
633
|
+
exchanges.push({
|
|
634
|
+
user: { entryId: event.entryId, text: event.text, retained },
|
|
635
|
+
...assistant ? { assistant } : {}
|
|
636
|
+
});
|
|
637
|
+
if (exchanges.length > MAX_RECENT_EXCHANGES) exchanges.shift();
|
|
638
|
+
}
|
|
639
|
+
assistant = void 0;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
visit(events, false);
|
|
644
|
+
visit(retainedTail, true);
|
|
645
|
+
return exchanges;
|
|
646
|
+
};
|
|
647
|
+
var dialogueExcerpts = (exchange) => {
|
|
648
|
+
const heading = (role, message) => `${role} [entry ${message.entryId}${message.retained ? "; retained raw" : ""}]:`;
|
|
649
|
+
const userHeading = heading("User instruction", exchange.user);
|
|
650
|
+
const assistantHeading = exchange.assistant ? heading("Historical assistant response (not a verified outcome)", exchange.assistant) : "";
|
|
651
|
+
const available = Math.max(0, MAX_EXCHANGE_BYTES - utf8Bytes(userHeading + assistantHeading) - 8);
|
|
652
|
+
const userText = exchange.user.retained ? "" : exchange.user.text;
|
|
653
|
+
const assistantBytes = exchange.assistant && !exchange.assistant.retained ? utf8Bytes(exchange.assistant.text) : 0;
|
|
654
|
+
const userBudget = exchange.assistant ? Math.max(available / 2, available - assistantBytes) : available;
|
|
655
|
+
const user = boundedExcerpt(userText, Math.floor(userBudget));
|
|
656
|
+
const excerpts = [{ heading: userHeading, ...user }];
|
|
657
|
+
if (exchange.assistant) {
|
|
658
|
+
const assistant = boundedExcerpt(
|
|
659
|
+
exchange.assistant.retained ? "" : exchange.assistant.text,
|
|
660
|
+
available - utf8Bytes(user.text)
|
|
661
|
+
);
|
|
662
|
+
excerpts.unshift({ heading: assistantHeading, ...assistant });
|
|
663
|
+
}
|
|
664
|
+
return excerpts;
|
|
665
|
+
};
|
|
666
|
+
var projectDialogue = (exchanges) => {
|
|
667
|
+
let omittedBytes = 0;
|
|
668
|
+
const lines = exchanges.map((exchange) => dialogueExcerpts(exchange).map((excerpt) => {
|
|
669
|
+
omittedBytes += excerpt.omittedBytes;
|
|
670
|
+
return `${excerpt.heading}
|
|
671
|
+
${excerpt.text}`;
|
|
672
|
+
}).join("\n\n"));
|
|
673
|
+
return { lines, omittedBytes };
|
|
674
|
+
};
|
|
675
|
+
|
|
618
676
|
// src/compaction/projections.ts
|
|
619
677
|
var MAX_LINE = 140;
|
|
620
678
|
var FILE_TOOLS = /* @__PURE__ */ new Set(["read", "edit", "write", "grep", "find", "ls"]);
|
|
621
679
|
var MODIFYING_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
622
|
-
var MAX_USER_GOAL_LINES = 3;
|
|
623
|
-
var MAX_USER_GOAL_LINE = 1024;
|
|
624
680
|
var MAX_USER_ONELINER = 120;
|
|
625
681
|
var MAX_EARLIER_USER = 80;
|
|
626
682
|
var MAX_STATUS_LINE = 140;
|
|
@@ -656,10 +712,6 @@ var customMessageLine = (event, maxText) => {
|
|
|
656
712
|
const visibility = event.display ? "visible" : "hidden";
|
|
657
713
|
return `custom ${quoted(event.customType, 80)} (${visibility}): ${quoted(event.text, maxText)}${customDetailsSuffix(event.details)}`;
|
|
658
714
|
};
|
|
659
|
-
var trailingEllipsis = (lines, max) => {
|
|
660
|
-
if (lines.length <= max) return lines;
|
|
661
|
-
return [...lines.slice(0, max), "\u2026"];
|
|
662
|
-
};
|
|
663
715
|
var pathOf = (args) => {
|
|
664
716
|
const value = args.path ?? args.file ?? args.dir;
|
|
665
717
|
return typeof value === "string" && value.trim() ? value : void 0;
|
|
@@ -745,27 +797,14 @@ var commonRoot = (paths) => {
|
|
|
745
797
|
return `${first.slice(0, common).join("/")}/`;
|
|
746
798
|
};
|
|
747
799
|
var stripRoot = (root, path) => root ? path.replace(root, "") : path;
|
|
748
|
-
var projectGoal = (events) => {
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
);
|
|
752
|
-
if (!first) return { lines: [], omitted: 0 };
|
|
753
|
-
const firstLines = first.text.split("\n").filter(
|
|
754
|
-
(line, i, arr) => line.trim() !== "" || i === 0 && arr.length === 1
|
|
755
|
-
).map((line) => truncate(line, MAX_USER_GOAL_LINE));
|
|
756
|
-
const lines = [...trailingEllipsis(firstLines, MAX_USER_GOAL_LINES)];
|
|
757
|
-
function* laterUsers() {
|
|
758
|
-
let skippedFirst = false;
|
|
800
|
+
var projectGoal = (events, protectedUsers) => {
|
|
801
|
+
const lines = [];
|
|
802
|
+
function* historicalUsers() {
|
|
759
803
|
for (const event of events) {
|
|
760
|
-
if (event.kind
|
|
761
|
-
if (!skippedFirst) {
|
|
762
|
-
skippedFirst = true;
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
yield event;
|
|
804
|
+
if (event.kind === "user" && !protectedUsers.has(event.entryId)) yield event;
|
|
766
805
|
}
|
|
767
806
|
}
|
|
768
|
-
const sampled = sampleAddressedFrom(
|
|
807
|
+
const sampled = sampleAddressedFrom(historicalUsers(), MAX_LATER_GOALS);
|
|
769
808
|
for (let index = 0; index < sampled.values.length; index++) {
|
|
770
809
|
if (sampled.omitted > 0 && index === sampled.splitIndex) {
|
|
771
810
|
lines.push(omissionLine(
|
|
@@ -1079,8 +1118,10 @@ var projectTranscript = (events) => {
|
|
|
1079
1118
|
}
|
|
1080
1119
|
return { lines, omitted };
|
|
1081
1120
|
};
|
|
1082
|
-
var projectWithMetadata = (events) => {
|
|
1083
|
-
const
|
|
1121
|
+
var projectWithMetadata = (events, retainedDialogue = []) => {
|
|
1122
|
+
const exchanges = recentDialogue(events, retainedDialogue);
|
|
1123
|
+
const dialogue = projectDialogue(exchanges);
|
|
1124
|
+
const goal = projectGoal(events, new Set(exchanges.map(({ user }) => user.entryId)));
|
|
1084
1125
|
const files = projectFiles(events);
|
|
1085
1126
|
const activity = projectActivity(events);
|
|
1086
1127
|
const outstanding = projectOutstandingWithMetadata(events);
|
|
@@ -1088,6 +1129,7 @@ var projectWithMetadata = (events) => {
|
|
|
1088
1129
|
const transcript = projectTranscript(events);
|
|
1089
1130
|
return {
|
|
1090
1131
|
sections: {
|
|
1132
|
+
dialogue: dialogue.lines,
|
|
1091
1133
|
goal: goal.lines,
|
|
1092
1134
|
files: files.lines,
|
|
1093
1135
|
activity: activity.lines,
|
|
@@ -1098,6 +1140,7 @@ var projectWithMetadata = (events) => {
|
|
|
1098
1140
|
},
|
|
1099
1141
|
omittedCounts: {
|
|
1100
1142
|
goal: goal.omitted,
|
|
1143
|
+
dialogueBytes: dialogue.omittedBytes,
|
|
1101
1144
|
files: files.omitted,
|
|
1102
1145
|
activity: activity.omitted,
|
|
1103
1146
|
outstanding: outstanding.omitted,
|
|
@@ -1108,8 +1151,9 @@ var projectWithMetadata = (events) => {
|
|
|
1108
1151
|
};
|
|
1109
1152
|
|
|
1110
1153
|
// src/compaction/render.ts
|
|
1111
|
-
var
|
|
1112
|
-
{ key: "
|
|
1154
|
+
var SUMMARY_SECTIONS = [
|
|
1155
|
+
{ key: "dialogue", header: "[Recent user directions and discussion]", maxBytes: 12288 },
|
|
1156
|
+
{ key: "goal", header: "[Historical requests]", maxBytes: 4096 },
|
|
1113
1157
|
{ key: "files", header: "[Files And Changes]", maxBytes: 4608 },
|
|
1114
1158
|
{ key: "activity", header: "[Fabric Activity]", maxBytes: 2048 },
|
|
1115
1159
|
{ key: "outstanding", header: "[Outstanding Context]", maxBytes: 4608 },
|
|
@@ -1142,42 +1186,89 @@ var boundedBlock = (header, sourceLines, maxBytes) => {
|
|
|
1142
1186
|
}
|
|
1143
1187
|
return clipUtf8(header, maxBytes);
|
|
1144
1188
|
};
|
|
1145
|
-
var
|
|
1189
|
+
var boundedHistory = (blocks, maxBytes) => {
|
|
1190
|
+
const candidates = blocks.map((block) => {
|
|
1191
|
+
const text = boundedBlock(block.header, block.lines, block.maxBytes);
|
|
1192
|
+
const bytes = utf8Bytes(text);
|
|
1193
|
+
const minimum2 = block.lines.length === 1 ? bytes : Math.min(bytes, utf8Bytes([block.header, ...sampledLines(block.lines, 0)].join("\n")));
|
|
1194
|
+
return { ...block, text, bytes, minimum: minimum2 };
|
|
1195
|
+
});
|
|
1196
|
+
const total = candidates.reduce((sum, block) => sum + block.bytes, 0);
|
|
1197
|
+
if (total <= maxBytes) return candidates.map(({ text }) => text);
|
|
1198
|
+
const minimum = candidates.reduce((sum, block) => sum + block.minimum, 0);
|
|
1199
|
+
let remaining = maxBytes - minimum;
|
|
1200
|
+
let demand = total - minimum;
|
|
1201
|
+
return candidates.map((block) => {
|
|
1202
|
+
const wanted = block.bytes - block.minimum;
|
|
1203
|
+
const extra = demand === 0 ? 0 : Math.min(wanted, Math.floor(remaining * wanted / demand));
|
|
1204
|
+
const text = boundedBlock(block.header, block.lines, block.minimum + extra);
|
|
1205
|
+
remaining -= utf8Bytes(text) - block.minimum;
|
|
1206
|
+
demand -= wanted;
|
|
1207
|
+
return text;
|
|
1208
|
+
});
|
|
1209
|
+
};
|
|
1210
|
+
var protectedBlock = (header, items, maxBytes) => {
|
|
1211
|
+
const text = [header, ...items].join("\n\n");
|
|
1212
|
+
if (utf8Bytes(text) <= maxBytes) return { text, omittedBytes: 0 };
|
|
1213
|
+
let remaining = Math.max(0, maxBytes - utf8Bytes(header) - 2 * items.length);
|
|
1214
|
+
const share = Math.floor(remaining / items.length);
|
|
1215
|
+
const budgets = items.map((item) => Math.min(utf8Bytes(item), share));
|
|
1216
|
+
remaining -= budgets.reduce((sum, bytes) => sum + bytes, 0);
|
|
1217
|
+
let omittedBytes = 0;
|
|
1218
|
+
const excerpts = items.map((item, index) => {
|
|
1219
|
+
const extra = Math.min(remaining, utf8Bytes(item) - budgets[index]);
|
|
1220
|
+
remaining -= extra;
|
|
1221
|
+
const excerpt = boundedExcerpt(item, budgets[index] + extra);
|
|
1222
|
+
omittedBytes += excerpt.omittedBytes;
|
|
1223
|
+
return excerpt.text;
|
|
1224
|
+
});
|
|
1225
|
+
return { text: [header, ...excerpts].join("\n\n"), omittedBytes };
|
|
1226
|
+
};
|
|
1227
|
+
var renderSummaryWithMetadata = (sections, options) => {
|
|
1146
1228
|
const blocks = [];
|
|
1147
|
-
|
|
1229
|
+
const history = [];
|
|
1230
|
+
let requestOmittedBytes = 0;
|
|
1231
|
+
let dialogueOmittedBytes = 0;
|
|
1232
|
+
const request = () => {
|
|
1233
|
+
if (!options.requestLines?.length) return;
|
|
1234
|
+
const rendered = protectedBlock("[Compaction Request]", options.requestLines, REQUEST_MAX_BYTES);
|
|
1235
|
+
blocks.push(rendered.text);
|
|
1236
|
+
requestOmittedBytes = rendered.omittedBytes;
|
|
1237
|
+
};
|
|
1238
|
+
for (const { key, header, maxBytes } of SUMMARY_SECTIONS) {
|
|
1148
1239
|
const lines = sections[key];
|
|
1149
|
-
if (
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1240
|
+
if (key === "dialogue") {
|
|
1241
|
+
if (lines.length > 0) {
|
|
1242
|
+
const rendered = protectedBlock(header, lines, maxBytes);
|
|
1243
|
+
blocks.push(rendered.text);
|
|
1244
|
+
dialogueOmittedBytes = rendered.omittedBytes;
|
|
1245
|
+
}
|
|
1246
|
+
request();
|
|
1247
|
+
} else if (lines.length > 0) {
|
|
1248
|
+
history.push({ header, lines, maxBytes });
|
|
1153
1249
|
}
|
|
1154
1250
|
}
|
|
1155
|
-
if (sections.goal.length === 0 && options.requestLines && options.requestLines.length > 0) {
|
|
1156
|
-
blocks.unshift(boundedBlock("[Compaction Request]", options.requestLines, REQUEST_MAX_BYTES));
|
|
1157
|
-
}
|
|
1158
1251
|
if (sections.transcript.length > 0) {
|
|
1159
|
-
|
|
1252
|
+
history.push({ header: "---", lines: sections.transcript, maxBytes: TRANSCRIPT_MAX_BYTES });
|
|
1160
1253
|
}
|
|
1161
1254
|
const timestamp = options.lastTimestamp || "(unknown time)";
|
|
1162
1255
|
const range = options.firstEntryId || options.lastEntryId ? `${options.firstEntryId || "(start)"} \u2192 ${options.lastEntryId || "(end)"}` : "(no entries)";
|
|
1163
1256
|
const footer = options.summaryKind === "branch" ? `[branch summarized ${timestamp}; structural source entries ${range}]` : `[compacted ${timestamp}; cumulative source entries ${range}]`;
|
|
1164
|
-
|
|
1257
|
+
const footerBlock = boundedBlock("---", [footer, POINTER_LINE], FOOTER_MAX_BYTES);
|
|
1258
|
+
const framingBytes = utf8Bytes(footerBlock) + 2 * (blocks.length + history.length) + 1;
|
|
1259
|
+
const protectedBytes = blocks.reduce((sum, block) => sum + utf8Bytes(block), 0);
|
|
1260
|
+
blocks.push(...boundedHistory(history, MAX_SUMMARY_BYTES - framingBytes - protectedBytes), footerBlock);
|
|
1165
1261
|
const summary = `${blocks.join("\n\n")}
|
|
1166
1262
|
`;
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1263
|
+
return {
|
|
1264
|
+
summary: utf8Bytes(summary) <= MAX_SUMMARY_BYTES ? summary : `${clipUtf8(summary, MAX_SUMMARY_BYTES - 1, "")}
|
|
1265
|
+
`,
|
|
1266
|
+
requestOmittedBytes,
|
|
1267
|
+
dialogueOmittedBytes
|
|
1268
|
+
};
|
|
1170
1269
|
};
|
|
1171
1270
|
|
|
1172
1271
|
// src/compaction/branch-summary.ts
|
|
1173
|
-
var SECTION_HEADERS = [
|
|
1174
|
-
{ key: "goal", header: "[Session Goal]" },
|
|
1175
|
-
{ key: "files", header: "[Files And Changes]" },
|
|
1176
|
-
{ key: "activity", header: "[Fabric Activity]" },
|
|
1177
|
-
{ key: "outstanding", header: "[Outstanding Context]" },
|
|
1178
|
-
{ key: "earlierTurns", header: "[Earlier Turns]" },
|
|
1179
|
-
{ key: "status", header: "[Current Status]" }
|
|
1180
|
-
];
|
|
1181
1272
|
var asJsonObject = (value) => {
|
|
1182
1273
|
try {
|
|
1183
1274
|
const cloned = JSON.parse(JSON.stringify(value));
|
|
@@ -1331,22 +1422,24 @@ var compileFabricBranchSummary = (entriesToSummarize, customInstructions, enrich
|
|
|
1331
1422
|
if (events.length === 0) return void 0;
|
|
1332
1423
|
const projected = projectWithMetadata(events);
|
|
1333
1424
|
runEnrichers(enrichers, events, projected.sections);
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const sections = SECTION_HEADERS.filter(({ key }) => projected.sections[key].length > 0).map(({ header }) => header);
|
|
1340
|
-
if (request.text) sections.splice(1, 0, "[Compaction Request]");
|
|
1341
|
-
const summary = renderSummary(projected.sections, {
|
|
1425
|
+
const sections = SUMMARY_SECTIONS.filter(({ key }) => projected.sections[key].length > 0).map(({ header }) => header);
|
|
1426
|
+
if (instructions.requestLines.length > 0) {
|
|
1427
|
+
sections.splice(projected.sections.dialogue.length > 0 ? 1 : 0, 0, "[Compaction Request]");
|
|
1428
|
+
}
|
|
1429
|
+
const rendered = renderSummaryWithMetadata(projected.sections, {
|
|
1342
1430
|
firstEntryId: entriesToSummarize[0]?.id ?? "",
|
|
1343
1431
|
lastEntryId: entriesToSummarize.at(-1)?.id ?? "",
|
|
1344
1432
|
lastTimestamp: entriesToSummarize.at(-1)?.timestamp ?? "",
|
|
1345
1433
|
...instructions.requestLines.length > 0 ? { requestLines: instructions.requestLines } : {},
|
|
1346
1434
|
summaryKind: "branch"
|
|
1347
1435
|
});
|
|
1436
|
+
const request = {
|
|
1437
|
+
text: instructions.requestLines.join("\n"),
|
|
1438
|
+
sourceBytes: instructions.policy.sourceBytes,
|
|
1439
|
+
truncated: instructions.policy.truncated || rendered.requestOmittedBytes > 0
|
|
1440
|
+
};
|
|
1348
1441
|
return {
|
|
1349
|
-
summary,
|
|
1442
|
+
summary: rendered.summary,
|
|
1350
1443
|
details: boundedDetails(entriesToSummarize, factsFromEvents(events), sections, request, oldLeafId)
|
|
1351
1444
|
};
|
|
1352
1445
|
};
|
|
@@ -1529,18 +1622,15 @@ var tokenCalibration = (branchEntries, tokensBefore, rawTokensBefore) => {
|
|
|
1529
1622
|
);
|
|
1530
1623
|
return { tokenScale, fixedOverheadTokens };
|
|
1531
1624
|
};
|
|
1625
|
+
var continuityTailLimit = (value) => value !== void 0 && Number.isSafeInteger(value) && value >= 0 ? value : DEFAULT_COMPACTION_SETTINGS.keepRecentTokens;
|
|
1532
1626
|
var continuityCutPlan = (branchEntries, tokensBefore, budget) => {
|
|
1533
|
-
if (!Number.isFinite(budget.contextWindow) || budget.contextWindow <= 0) return void 0;
|
|
1627
|
+
if (typeof budget.contextWindow !== "number" || !Number.isFinite(budget.contextWindow) || budget.contextWindow <= 0 || typeof budget.targetContextRatio !== "number" || !Number.isFinite(budget.targetContextRatio)) return void 0;
|
|
1534
1628
|
const contextWindow = Math.floor(budget.contextWindow);
|
|
1535
1629
|
const reserveTokens = Math.max(0, Math.floor(budget.reserveTokens));
|
|
1536
|
-
const keepRecentTokens =
|
|
1630
|
+
const keepRecentTokens = continuityTailLimit(budget.keepRecentTokens);
|
|
1537
1631
|
const targetContextRatio = Math.max(0.25, Math.min(0.85, budget.targetContextRatio));
|
|
1538
1632
|
const rawTokensBefore = rawContextTokens(branchEntries);
|
|
1539
|
-
const { tokenScale, fixedOverheadTokens } = tokenCalibration(
|
|
1540
|
-
branchEntries,
|
|
1541
|
-
tokensBefore,
|
|
1542
|
-
rawTokensBefore
|
|
1543
|
-
);
|
|
1633
|
+
const { tokenScale, fixedOverheadTokens } = budget.calibrateUsage === false ? { tokenScale: 1, fixedOverheadTokens: 0 } : tokenCalibration(branchEntries, tokensBefore, rawTokensBefore);
|
|
1544
1634
|
const continuityTargetTokens = Math.max(1, Math.ceil(
|
|
1545
1635
|
fixedOverheadTokens + (keepRecentTokens + SUMMARY_RAW_TOKEN_BUDGET) * tokenScale
|
|
1546
1636
|
));
|
|
@@ -1593,7 +1683,7 @@ var boundary = (summarized, firstKeptEntryId, budget) => {
|
|
|
1593
1683
|
...budget ? { budget } : {}
|
|
1594
1684
|
};
|
|
1595
1685
|
};
|
|
1596
|
-
var computeContinuityCut = (branchEntries, live, plan) => {
|
|
1686
|
+
var computeContinuityCut = (branchEntries, live, plan, rawTailTokenBudget = plan?.rawTailTokenBudget ?? DEFAULT_COMPACTION_SETTINGS.keepRecentTokens) => {
|
|
1597
1687
|
const suffixTokens = new Array(live.length + 1).fill(0);
|
|
1598
1688
|
for (let index = live.length - 1; index >= 0; index--) {
|
|
1599
1689
|
suffixTokens[index] = suffixTokens[index + 1] + live[index].estimatedTokens;
|
|
@@ -1604,13 +1694,13 @@ var computeContinuityCut = (branchEntries, live, plan) => {
|
|
|
1604
1694
|
for (let index = 1; index < live.length; index++) {
|
|
1605
1695
|
const item = live[index];
|
|
1606
1696
|
if (item.branchIndex <= previousCompactionIndex) continue;
|
|
1607
|
-
if (!item.cutPoint || suffixTokens[index] >
|
|
1697
|
+
if (!item.cutPoint || suffixTokens[index] > rawTailTokenBudget) continue;
|
|
1608
1698
|
if (!closureSafe(spans, item.branchIndex)) continue;
|
|
1609
1699
|
cutIndex = index;
|
|
1610
1700
|
break;
|
|
1611
1701
|
}
|
|
1612
1702
|
const retainedRawTokens = suffixTokens[cutIndex] ?? 0;
|
|
1613
|
-
const details = {
|
|
1703
|
+
const details = plan ? {
|
|
1614
1704
|
strategy: "continuity",
|
|
1615
1705
|
contextWindow: plan.contextWindow,
|
|
1616
1706
|
targetContextRatio: plan.targetContextRatio,
|
|
@@ -1627,7 +1717,7 @@ var computeContinuityCut = (branchEntries, live, plan) => {
|
|
|
1627
1717
|
reductionCeilingTokens: plan.reductionCeilingTokens,
|
|
1628
1718
|
rawTailTokenBudget: plan.rawTailTokenBudget,
|
|
1629
1719
|
bindingConstraint: plan.bindingConstraint
|
|
1630
|
-
};
|
|
1720
|
+
} : void 0;
|
|
1631
1721
|
if (cutIndex >= live.length) {
|
|
1632
1722
|
return boundary(live.map((item) => item.entry), "", details);
|
|
1633
1723
|
}
|
|
@@ -1645,8 +1735,12 @@ var computeCut = (branchEntries, options) => {
|
|
|
1645
1735
|
if (plan) return computeContinuityCut(branchEntries, live, plan);
|
|
1646
1736
|
}
|
|
1647
1737
|
const lastBoundary = lastBoundaryIndex(live);
|
|
1648
|
-
|
|
1649
|
-
const
|
|
1738
|
+
const closed = lastBoundary > 0 ? closeCut(branchEntries, live, lastBoundary) : 0;
|
|
1739
|
+
const keepRecentTokens = continuityTailLimit(options?.budget.keepRecentTokens);
|
|
1740
|
+
const tailTokens = live.slice(closed).reduce((sum, item) => sum + item.estimatedTokens, 0);
|
|
1741
|
+
if (tailTokens > keepRecentTokens) {
|
|
1742
|
+
return computeContinuityCut(branchEntries, live, void 0, keepRecentTokens);
|
|
1743
|
+
}
|
|
1650
1744
|
const previousCompactionIndex = findLastCompaction(branchEntries)?.index ?? -1;
|
|
1651
1745
|
if (closed <= 0 || live[closed].branchIndex <= previousCompactionIndex) {
|
|
1652
1746
|
return boundary(live.map((item) => item.entry), "");
|
|
@@ -1708,7 +1802,7 @@ var isFabricV2Details = (value) => {
|
|
|
1708
1802
|
"earlierTurns",
|
|
1709
1803
|
"transcript",
|
|
1710
1804
|
"preserve"
|
|
1711
|
-
]) && (value.omittedCounts.activity === void 0 || typeof value.omittedCounts.activity === "number" && Number.isFinite(value.omittedCounts.activity)) && (value.omittedCounts.commits === void 0 || typeof value.omittedCounts.commits === "number" && Number.isFinite(value.omittedCounts.commits)) && (value.omittedCounts.thinking === void 0 || typeof value.omittedCounts.thinking === "number" && Number.isFinite(value.omittedCounts.thinking)) && typeof value.instructionPolicy.mode === "string" && instructionModes.has(value.instructionPolicy.mode) && typeof value.instructionPolicy.canonicalized === "boolean" && typeof value.instructionPolicy.truncated === "boolean" && hasFiniteNumbers(value.instructionPolicy, [
|
|
1805
|
+
]) && (value.omittedCounts.activity === void 0 || typeof value.omittedCounts.activity === "number" && Number.isFinite(value.omittedCounts.activity)) && (value.omittedCounts.commits === void 0 || typeof value.omittedCounts.commits === "number" && Number.isFinite(value.omittedCounts.commits)) && (value.omittedCounts.thinking === void 0 || typeof value.omittedCounts.thinking === "number" && Number.isFinite(value.omittedCounts.thinking)) && (value.omittedCounts.dialogueBytes === void 0 || typeof value.omittedCounts.dialogueBytes === "number" && Number.isFinite(value.omittedCounts.dialogueBytes) && value.omittedCounts.dialogueBytes >= 0) && (value.instructionPolicy.renderedOmittedBytes === void 0 || typeof value.instructionPolicy.renderedOmittedBytes === "number" && Number.isFinite(value.instructionPolicy.renderedOmittedBytes) && value.instructionPolicy.renderedOmittedBytes >= 0) && typeof value.instructionPolicy.mode === "string" && instructionModes.has(value.instructionPolicy.mode) && typeof value.instructionPolicy.canonicalized === "boolean" && typeof value.instructionPolicy.truncated === "boolean" && hasFiniteNumbers(value.instructionPolicy, [
|
|
1712
1806
|
"sourceBytes",
|
|
1713
1807
|
"preserveCount",
|
|
1714
1808
|
"omittedPreserveCount"
|
|
@@ -1764,15 +1858,17 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1764
1858
|
if (!cut.ok) return { cancel: true, reason: "fabric: nothing to compact" };
|
|
1765
1859
|
const source = cumulativeSource(branchEntries, cut.firstKeptEntryId);
|
|
1766
1860
|
if (source.events.length === 0) return { cancel: true, reason: "fabric: no raw cumulative source" };
|
|
1767
|
-
const
|
|
1861
|
+
const retainedDialogue = cut.firstKeptEntryId ? normalizeEntries(branchEntries.slice(source.prefixEntries.length).filter((entry) => entry.type === "message" && (entry.message.role === "user" || entry.message.role === "assistant"))).filter((event) => event.kind === "user" || event.kind === "assistantText") : [];
|
|
1862
|
+
const projected = projectWithMetadata(source.events, retainedDialogue);
|
|
1768
1863
|
const sections = projected.sections;
|
|
1769
1864
|
runEnrichers(enrichers, source.events, sections);
|
|
1770
|
-
const
|
|
1865
|
+
const rendered = renderSummaryWithMetadata(sections, {
|
|
1771
1866
|
firstEntryId: source.range.first,
|
|
1772
1867
|
lastEntryId: source.range.last,
|
|
1773
1868
|
lastTimestamp: source.timestamp,
|
|
1774
1869
|
requestLines: instructions.requestLines
|
|
1775
1870
|
});
|
|
1871
|
+
const { summary } = rendered;
|
|
1776
1872
|
const projectedTokensAfter = cut.budget ? Math.ceil(
|
|
1777
1873
|
cut.budget.fixedOverheadTokens + (cut.budget.retainedRawTokens + Math.ceil(summary.length / 4)) * cut.budget.tokenScale
|
|
1778
1874
|
) : void 0;
|
|
@@ -1784,8 +1880,10 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1784
1880
|
};
|
|
1785
1881
|
}
|
|
1786
1882
|
const versions = priorFabricVersions(branchEntries);
|
|
1787
|
-
const sectionHeaders =
|
|
1788
|
-
if (instructions.requestLines.length > 0)
|
|
1883
|
+
const sectionHeaders = SUMMARY_SECTIONS.filter(({ key }) => sections[key].length > 0).map(({ header }) => header);
|
|
1884
|
+
if (instructions.requestLines.length > 0) {
|
|
1885
|
+
sectionHeaders.splice(sections.dialogue.length > 0 ? 1 : 0, 0, "[Compaction Request]");
|
|
1886
|
+
}
|
|
1789
1887
|
const details = {
|
|
1790
1888
|
compactor: "fabric",
|
|
1791
1889
|
version: 2,
|
|
@@ -1807,13 +1905,18 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1807
1905
|
},
|
|
1808
1906
|
omittedCounts: {
|
|
1809
1907
|
...projected.omittedCounts,
|
|
1908
|
+
dialogueBytes: (projected.omittedCounts.dialogueBytes ?? 0) + rendered.dialogueOmittedBytes,
|
|
1810
1909
|
preserve: instructions.policy.omittedPreserveCount,
|
|
1811
1910
|
// Thinking parts never survive normalization into a rendered summary;
|
|
1812
1911
|
// the structural count keeps that erasure auditable against the raw
|
|
1813
1912
|
// prefix instead of letting deliberation vanish untracked.
|
|
1814
1913
|
thinking: countErasedThinkingBlocks(source.prefixEntries)
|
|
1815
1914
|
},
|
|
1816
|
-
instructionPolicy:
|
|
1915
|
+
instructionPolicy: {
|
|
1916
|
+
...instructions.policy,
|
|
1917
|
+
truncated: instructions.policy.truncated || rendered.requestOmittedBytes > 0,
|
|
1918
|
+
renderedOmittedBytes: rendered.requestOmittedBytes
|
|
1919
|
+
},
|
|
1817
1920
|
stableAddresses: {
|
|
1818
1921
|
firstKeptEntryId: cut.firstKeptEntryId,
|
|
1819
1922
|
cumulativeSourceRange: source.range,
|
|
@@ -1831,14 +1934,6 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1831
1934
|
}
|
|
1832
1935
|
};
|
|
1833
1936
|
};
|
|
1834
|
-
var SECTION_HEADERS2 = [
|
|
1835
|
-
{ key: "goal", header: "[Session Goal]" },
|
|
1836
|
-
{ key: "files", header: "[Files And Changes]" },
|
|
1837
|
-
{ key: "activity", header: "[Fabric Activity]" },
|
|
1838
|
-
{ key: "outstanding", header: "[Outstanding Context]" },
|
|
1839
|
-
{ key: "earlierTurns", header: "[Earlier Turns]" },
|
|
1840
|
-
{ key: "status", header: "[Current Status]" }
|
|
1841
|
-
];
|
|
1842
1937
|
var notifyInstructionError = (context, error) => {
|
|
1843
1938
|
if (!context?.hasUI) return;
|
|
1844
1939
|
context.ui.notify(clipUtf8(`Fabric compaction rejected: ${error.code}: ${error.message}`, 512), "error");
|
|
@@ -1864,12 +1959,12 @@ var registerCompactionHook = (pi, options) => {
|
|
|
1864
1959
|
const evidenceWindow = event.reason === "overflow" && typeof tokensBefore === "number" && Number.isFinite(tokensBefore) && tokensBefore > 0 ? Math.max(1, Math.floor(tokensBefore * OVERFLOW_WINDOW_EVIDENCE_RATIO)) : void 0;
|
|
1865
1960
|
const advertisedWindow = typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? contextWindow : void 0;
|
|
1866
1961
|
const effectiveWindow = evidenceWindow === void 0 ? advertisedWindow : advertisedWindow === void 0 ? evidenceWindow : Math.min(advertisedWindow, evidenceWindow);
|
|
1867
|
-
const budget =
|
|
1868
|
-
contextWindow: effectiveWindow,
|
|
1869
|
-
targetContextRatio,
|
|
1962
|
+
const budget = {
|
|
1963
|
+
...effectiveWindow !== void 0 ? { contextWindow: effectiveWindow } : {},
|
|
1964
|
+
...typeof targetContextRatio === "number" && Number.isFinite(targetContextRatio) ? { targetContextRatio } : {},
|
|
1870
1965
|
reserveTokens: settings.reserveTokens,
|
|
1871
1966
|
keepRecentTokens: settings.keepRecentTokens
|
|
1872
|
-
}
|
|
1967
|
+
};
|
|
1873
1968
|
const result = compileFabricSummary(
|
|
1874
1969
|
branchEntries ?? [],
|
|
1875
1970
|
preparation.tokensBefore,
|
|
@@ -1921,4 +2016,4 @@ export {
|
|
|
1921
2016
|
compileFabricSummary,
|
|
1922
2017
|
registerCompactionHook
|
|
1923
2018
|
};
|
|
1924
|
-
//# sourceMappingURL=chunk-
|
|
2019
|
+
//# sourceMappingURL=chunk-SRZPJBNP.js.map
|