@e4779/pi-fabric 0.92.41-fork.6 → 0.96.4-fork.10
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/LAWS.bend +502 -0
- package/PROOF.bend +452 -0
- package/README.md +5 -1
- package/THIRD_PARTY_NOTICES.md +9 -0
- 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 +6 -5
- package/dist/agents.js.map +1 -1
- package/dist/chunks/{chunk-3TXOQ5MG.js → chunk-3CJETB4S.js} +828 -204
- package/dist/chunks/chunk-3CJETB4S.js.map +7 -0
- package/dist/chunks/{chunk-IUCVOZRX.js → chunk-3SIXBW6A.js} +2 -2
- package/dist/chunks/chunk-4E63LJDD.js +468 -0
- package/dist/chunks/chunk-4E63LJDD.js.map +7 -0
- package/dist/chunks/{chunk-AAHHYDTO.js → chunk-4NF3S3NM.js} +1 -1
- package/dist/chunks/{chunk-AAHHYDTO.js.map → chunk-4NF3S3NM.js.map} +2 -2
- package/dist/chunks/{chunk-2SWRVIYJ.js → chunk-754HA6KO.js} +2 -2
- package/dist/chunks/{chunk-K6DHXXF5.js → chunk-B2IVWASP.js} +2 -2
- package/dist/chunks/{chunk-ZDNGXLEC.js → chunk-B4HECUJI.js} +2 -2
- package/dist/chunks/{chunk-H6DDV6E2.js → chunk-CSJSHBAT.js} +5 -5
- package/dist/chunks/{chunk-MW5VI7IW.js → chunk-D4B4CCTA.js} +2 -2
- package/dist/chunks/{chunk-EDL4JDW7.js → chunk-EBWMC3OO.js} +2 -2
- package/dist/chunks/{chunk-4NUTVNS2.js → chunk-F72MAIQY.js} +31 -368
- package/dist/chunks/chunk-F72MAIQY.js.map +7 -0
- package/dist/chunks/{chunk-W3FRE4VI.js → chunk-FDIEQEXS.js} +2 -2
- package/dist/chunks/{chunk-7A6NVHB5.js → chunk-FJSHRHOR.js} +7 -4
- package/dist/chunks/chunk-FJSHRHOR.js.map +7 -0
- package/dist/chunks/{chunk-PSNXUZMY.js → chunk-G2F2RDZI.js} +5 -47
- package/dist/chunks/chunk-G2F2RDZI.js.map +7 -0
- package/dist/chunks/{chunk-3WIGAX56.js → chunk-JCV54SSP.js} +2 -2
- package/dist/chunks/chunk-KS44WKJJ.js +51 -0
- package/dist/chunks/chunk-KS44WKJJ.js.map +7 -0
- package/dist/chunks/{chunk-3H7SDWZI.js → chunk-LNLQ2LX3.js} +22 -1
- package/dist/chunks/chunk-LNLQ2LX3.js.map +7 -0
- package/dist/chunks/{chunk-G4LADAYY.js → chunk-OINADFEF.js} +8 -3
- package/dist/chunks/chunk-OINADFEF.js.map +7 -0
- package/dist/chunks/{chunk-UQ4LTUH4.js → chunk-OUAC6O5C.js} +36 -9
- package/dist/chunks/chunk-OUAC6O5C.js.map +7 -0
- package/dist/chunks/{chunk-MQG5QKGI.js → chunk-Q5BMTL6A.js} +217 -95
- package/dist/chunks/chunk-Q5BMTL6A.js.map +7 -0
- package/dist/chunks/{chunk-IK6PPFWG.js → chunk-QFKHAAZA.js} +11 -11
- package/dist/chunks/chunk-QFKHAAZA.js.map +7 -0
- package/dist/chunks/{chunk-RTXZHKMS.js → chunk-QNMQJNXE.js} +7 -3
- package/dist/chunks/chunk-QNMQJNXE.js.map +7 -0
- package/dist/chunks/{chunk-U5FYOMG5.js → chunk-UBPFGMDQ.js} +6 -2
- package/dist/chunks/chunk-UBPFGMDQ.js.map +7 -0
- package/dist/chunks/{chunk-FLKGJPCN.js → chunk-ULQFHZJE.js} +4 -1
- package/dist/chunks/chunk-ULQFHZJE.js.map +7 -0
- package/dist/chunks/{chunk-7VAZ4N43.js → chunk-V3PIO7QL.js} +2 -2
- package/dist/chunks/{chunk-MGDLRV2R.js → chunk-VQGO4P7C.js} +2 -2
- package/dist/chunks/{chunk-XT4346N7.js → chunk-WXSELMFV.js} +9 -3
- package/dist/chunks/chunk-WXSELMFV.js.map +7 -0
- package/dist/chunks/{chunk-D5WKZONW.js → chunk-X3IRR7CV.js} +2 -2
- package/dist/chunks/{chunk-IJL3QK3J.js → chunk-Y57UHPIK.js} +1 -1
- package/dist/chunks/{chunk-IJL3QK3J.js.map → chunk-Y57UHPIK.js.map} +1 -1
- package/dist/chunks/{chunk-RKRVOBVO.js → chunk-YC3QQDZ3.js} +2 -2
- package/dist/chunks/{chunk-Q4XJ4PYL.js → chunk-ZRI433JP.js} +299 -83
- package/dist/chunks/chunk-ZRI433JP.js.map +7 -0
- package/dist/chunks/{chunk-36B4AIRT.js → chunk-ZTXZ6JDO.js} +2 -2
- package/dist/commands/fabric.d.ts.map +1 -1
- 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 +6 -2
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +6 -5
- 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/components/configuration.js +2 -3
- package/dist/components/effect-policy.d.ts +2 -0
- package/dist/components/effect-policy.d.ts.map +1 -1
- package/dist/components/effect-scope.d.ts.map +1 -1
- package/dist/components/supervisor.d.ts +1 -1
- package/dist/components/supervisor.d.ts.map +1 -1
- package/dist/core/action-registry.d.ts +14 -2
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +7 -5
- package/dist/core/provider-bindings.d.ts +8 -2
- package/dist/core/provider-bindings.d.ts.map +1 -1
- package/dist/core/provider-operations.d.ts +28 -0
- package/dist/core/provider-operations.d.ts.map +1 -0
- package/dist/core/provider-operations.js +201 -0
- package/dist/core/provider-operations.js.map +7 -0
- package/dist/core/shell-inbox.d.ts +13 -0
- package/dist/core/shell-inbox.d.ts.map +1 -0
- package/dist/core/shell-jobs.d.ts +51 -7
- package/dist/core/shell-jobs.d.ts.map +1 -1
- package/dist/core/shell-limits.d.ts +3 -0
- package/dist/core/shell-limits.d.ts.map +1 -0
- package/dist/core/shell-monitor.d.ts +51 -0
- package/dist/core/shell-monitor.d.ts.map +1 -0
- package/dist/entropy/index.js +8 -7
- package/dist/entropy/normal-form.d.ts.map +1 -1
- package/dist/execution-service.d.ts +1 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts +1 -1
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +1124 -325
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/index.js +155 -44
- package/dist/index.js.map +3 -3
- package/dist/jev/observation.js +5 -3
- package/dist/jev.d.ts +0 -1
- package/dist/jev.d.ts.map +1 -1
- package/dist/jev.js +9 -13
- package/dist/memory/digest.d.ts.map +1 -1
- package/dist/memory/digest.js +2 -1
- package/dist/memory/discovery.js +6 -5
- package/dist/memory/expand-service.d.ts.map +1 -1
- package/dist/memory/file-worker.js +9 -8
- package/dist/memory/file-worker.js.map +1 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/normalize.d.ts.map +1 -1
- package/dist/memory/normalize.js +5 -4
- package/dist/memory/search.js +7 -6
- package/dist/memory/worker-provider.js +10 -9
- package/dist/memory.js +9 -8
- package/dist/memory.js.map +1 -1
- package/dist/mesh/store.d.ts.map +1 -1
- package/dist/prewalk/handoff.d.ts +1 -1
- package/dist/prewalk/handoff.d.ts.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/providers/jev-provider.d.ts +1 -1
- package/dist/providers/jev-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +9 -7
- package/dist/providers/memory-provider.js +9 -8
- package/dist/providers/pi-tools-provider.d.ts.map +1 -1
- package/dist/providers/tasks-provider.d.ts +12 -0
- package/dist/providers/tasks-provider.d.ts.map +1 -0
- package/dist/residency/host.js +10 -9
- package/dist/residency/pi-entry.js +10 -9
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/guest-types.d.ts +1 -1
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/monty-runtime.js +1 -2
- package/dist/runtime/monty-runtime.js.map +1 -1
- package/dist/runtime/typescript-kernel.js +2 -2
- package/dist/runtime-state-builtins.d.ts +1 -1
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/schema/controller.d.ts.map +1 -1
- package/dist/state/store.d.ts.map +1 -1
- package/dist/ui/controller.d.ts +1 -0
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-targets.js +2 -2
- package/dist/ui/conversation.js +7 -7
- package/dist/ui/dashboard.js +9 -9
- package/dist/ui/highlight.d.ts.map +1 -1
- package/dist/ui/languages/bend.d.ts +4 -0
- package/dist/ui/languages/bend.d.ts.map +1 -0
- package/dist/ui/languages/bend.js +73 -0
- package/dist/ui/languages/bend.js.map +7 -0
- package/dist/ui/settings.js +1 -2
- package/dist/ui/settings.js.map +1 -1
- package/dist/ui/shell-hang-keys.d.ts.map +1 -1
- package/dist/ui/shell-tasks.d.ts +22 -0
- package/dist/ui/shell-tasks.d.ts.map +1 -0
- package/dist/ui/shell-tasks.js +161 -0
- package/dist/ui/shell-tasks.js.map +7 -0
- package/dist/ui/shiki-catalog.d.ts +2 -1
- package/dist/ui/shiki-catalog.d.ts.map +1 -1
- package/dist/ui/snapshot.d.ts.map +1 -1
- package/dist/ui/types.d.ts +1 -0
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/verified/authority.d.ts +17 -0
- package/dist/verified/authority.d.ts.map +1 -0
- package/dist/verified/generated/authority-kernel.d.ts +10 -0
- package/dist/verified/generated/authority-kernel.js +116 -0
- package/dist/verified/generated/kernel.d.ts +31 -0
- package/dist/verified/generated/kernel.js +351 -0
- package/dist/verified/generated/lifecycle-kernel.d.ts +7 -0
- package/dist/verified/generated/lifecycle-kernel.js +155 -0
- package/dist/verified/generated/manifest.json +54 -0
- package/dist/verified/generated/provider-kernel.d.ts +9 -0
- package/dist/verified/generated/provider-kernel.js +80 -0
- package/dist/verified/generated/storage-kernel.d.ts +11 -0
- package/dist/verified/generated/storage-kernel.js +98 -0
- package/dist/verified/memory.d.ts +11 -0
- package/dist/verified/memory.d.ts.map +1 -0
- package/dist/verified/nat.d.ts +2 -0
- package/dist/verified/nat.d.ts.map +1 -0
- package/dist/verified/policy.d.ts +37 -0
- package/dist/verified/policy.d.ts.map +1 -0
- package/dist/verified/resources.d.ts +14 -0
- package/dist/verified/resources.d.ts.map +1 -0
- package/dist/verified/storage.d.ts +32 -0
- package/dist/verified/storage.d.ts.map +1 -0
- package/dist/worker/event-projection.d.ts +6 -0
- package/dist/worker/event-projection.d.ts.map +1 -0
- package/dist/worker/event-projection.js +99 -0
- package/dist/worker/event-projection.js.map +7 -0
- package/dist/worker/recovery-watchdog.d.ts +12 -0
- package/dist/worker/recovery-watchdog.d.ts.map +1 -0
- package/dist/worker/recovery-watchdog.js +41 -0
- package/dist/worker/recovery-watchdog.js.map +7 -0
- package/dist/worker.js +80 -22
- package/dist/worker.js.map +2 -2
- package/docs/agents.md +26 -14
- package/docs/architecture.md +1 -1
- package/docs/background-tasks.md +140 -0
- package/docs/compaction.md +91 -28
- package/docs/components.md +5 -1
- package/docs/configuration.md +6 -6
- package/docs/foreman.md +4 -4
- package/docs/harnesses.md +95 -0
- package/docs/interface.md +7 -0
- package/docs/jev.md +59 -52
- package/docs/kernels.md +2 -2
- package/docs/licenses/bend-apache-2.0.txt +202 -0
- package/docs/memory-recall.md +1 -1
- package/docs/programmatic-compaction.md +13 -2
- package/docs/provider-capabilities.md +197 -0
- package/docs/shell-middleware.md +3 -3
- package/docs/skills.md +1 -1
- package/docs/verified-kernels.md +278 -0
- package/package.json +14 -4
- package/proofs/abi.json +308 -0
- package/proofs/authority-abi.json +7 -0
- package/proofs/authority-kernel.bend +23 -0
- package/proofs/authority-proof.bend +74 -0
- package/proofs/authority-spec.bend +30 -0
- package/proofs/authority-state.bend +43 -0
- package/proofs/authority-types.d.ts +3 -0
- package/proofs/kernel.bend +139 -0
- package/proofs/lifecycle-abi.json +3 -0
- package/proofs/lifecycle-kernel.bend +11 -0
- package/proofs/lifecycle-proof.bend +249 -0
- package/proofs/lifecycle-spec.bend +261 -0
- package/proofs/lifecycle-types.d.ts +4 -0
- package/proofs/lifecycle.bend +119 -0
- package/proofs/provider-abi.json +4 -0
- package/proofs/provider-kernel.bend +14 -0
- package/proofs/provider-plans.bend +28 -0
- package/proofs/provider-spec.bend +14 -0
- package/proofs/provider-types.d.ts +5 -0
- package/proofs/resource-proof.bend +633 -0
- package/proofs/resource-spec.bend +133 -0
- package/proofs/resources.bend +160 -0
- package/proofs/state-kernel.bend +17 -0
- package/proofs/state-plans.bend +40 -0
- package/proofs/state-proof.bend +42 -0
- package/proofs/state-spec.bend +26 -0
- package/proofs/storage-abi.json +3 -0
- package/proofs/storage-kernel.bend +11 -0
- package/proofs/storage-plans.bend +100 -0
- package/proofs/storage-proof.bend +176 -0
- package/proofs/storage-spec.bend +70 -0
- package/proofs/storage-types.d.ts +8 -0
- package/proofs/types.d.ts +7 -0
- package/scripts/test-verified-kernels.mjs +107 -0
- package/scripts/verified-kernels.mjs +136 -0
- package/skillsets/python/fabric-jev/SKILL.md +13 -9
- package/skillsets/typescript/fabric-exec/SKILL.md +4 -2
- package/skillsets/typescript/fabric-jev/SKILL.md +13 -9
- package/dist/chunks/chunk-3H7SDWZI.js.map +0 -7
- package/dist/chunks/chunk-3TXOQ5MG.js.map +0 -7
- package/dist/chunks/chunk-4NUTVNS2.js.map +0 -7
- package/dist/chunks/chunk-77PDIBK2.js +0 -129
- package/dist/chunks/chunk-77PDIBK2.js.map +0 -7
- package/dist/chunks/chunk-7A6NVHB5.js.map +0 -7
- package/dist/chunks/chunk-FLKGJPCN.js.map +0 -7
- package/dist/chunks/chunk-G4LADAYY.js.map +0 -7
- package/dist/chunks/chunk-IK6PPFWG.js.map +0 -7
- package/dist/chunks/chunk-MQG5QKGI.js.map +0 -7
- package/dist/chunks/chunk-PSNXUZMY.js.map +0 -7
- package/dist/chunks/chunk-Q4XJ4PYL.js.map +0 -7
- package/dist/chunks/chunk-RTXZHKMS.js.map +0 -7
- package/dist/chunks/chunk-U5FYOMG5.js.map +0 -7
- package/dist/chunks/chunk-UQ4LTUH4.js.map +0 -7
- package/dist/chunks/chunk-XT4346N7.js.map +0 -7
- package/dist/jev/browser.d.ts +0 -37
- package/dist/jev/browser.d.ts.map +0 -1
- package/dist/jev/browser.js +0 -13
- package/dist/jev/browser.js.map +0 -7
- /package/dist/chunks/{chunk-IUCVOZRX.js.map → chunk-3SIXBW6A.js.map} +0 -0
- /package/dist/chunks/{chunk-2SWRVIYJ.js.map → chunk-754HA6KO.js.map} +0 -0
- /package/dist/chunks/{chunk-K6DHXXF5.js.map → chunk-B2IVWASP.js.map} +0 -0
- /package/dist/chunks/{chunk-ZDNGXLEC.js.map → chunk-B4HECUJI.js.map} +0 -0
- /package/dist/chunks/{chunk-H6DDV6E2.js.map → chunk-CSJSHBAT.js.map} +0 -0
- /package/dist/chunks/{chunk-MW5VI7IW.js.map → chunk-D4B4CCTA.js.map} +0 -0
- /package/dist/chunks/{chunk-EDL4JDW7.js.map → chunk-EBWMC3OO.js.map} +0 -0
- /package/dist/chunks/{chunk-W3FRE4VI.js.map → chunk-FDIEQEXS.js.map} +0 -0
- /package/dist/chunks/{chunk-3WIGAX56.js.map → chunk-JCV54SSP.js.map} +0 -0
- /package/dist/chunks/{chunk-7VAZ4N43.js.map → chunk-V3PIO7QL.js.map} +0 -0
- /package/dist/chunks/{chunk-MGDLRV2R.js.map → chunk-VQGO4P7C.js.map} +0 -0
- /package/dist/chunks/{chunk-D5WKZONW.js.map → chunk-X3IRR7CV.js.map} +0 -0
- /package/dist/chunks/{chunk-RKRVOBVO.js.map → chunk-YC3QQDZ3.js.map} +0 -0
- /package/dist/chunks/{chunk-36B4AIRT.js.map → chunk-ZTXZ6JDO.js.map} +0 -0
|
@@ -10,16 +10,21 @@ import {
|
|
|
10
10
|
FABRIC_BRANCH_SUMMARY_VERSION,
|
|
11
11
|
readFabricBranchSummaryDetails,
|
|
12
12
|
readFabricProjectionTrace
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-B4HECUJI.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-LNLQ2LX3.js";
|
|
24
|
+
import {
|
|
25
|
+
acceptCompactionCut,
|
|
26
|
+
acceptSummaryBounds
|
|
27
|
+
} from "./chunk-4E63LJDD.js";
|
|
23
28
|
|
|
24
29
|
// src/compaction/hook.ts
|
|
25
30
|
import "@earendil-works/pi-coding-agent";
|
|
@@ -615,12 +620,67 @@ var countErasedThinkingBlocks = (entries) => {
|
|
|
615
620
|
return count;
|
|
616
621
|
};
|
|
617
622
|
|
|
623
|
+
// src/compaction/dialogue.ts
|
|
624
|
+
var MAX_RECENT_EXCHANGES = 3;
|
|
625
|
+
var MAX_EXCHANGE_BYTES = 3968;
|
|
626
|
+
var recentDialogue = (events, retainedTail = []) => {
|
|
627
|
+
const exchanges = [];
|
|
628
|
+
let assistant;
|
|
629
|
+
const visit = (source, retained) => {
|
|
630
|
+
for (const event of source) {
|
|
631
|
+
if (event.kind === "assistantText" && event.text.trim()) {
|
|
632
|
+
if (assistant?.entryId === event.entryId) assistant.text += `
|
|
633
|
+
${event.text}`;
|
|
634
|
+
else assistant = { entryId: event.entryId, text: event.text, retained };
|
|
635
|
+
} else if (event.kind === "user") {
|
|
636
|
+
if (!retained || assistant?.retained === false) {
|
|
637
|
+
exchanges.push({
|
|
638
|
+
user: { entryId: event.entryId, text: event.text, retained },
|
|
639
|
+
...assistant ? { assistant } : {}
|
|
640
|
+
});
|
|
641
|
+
if (exchanges.length > MAX_RECENT_EXCHANGES) exchanges.shift();
|
|
642
|
+
}
|
|
643
|
+
assistant = void 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
visit(events, false);
|
|
648
|
+
visit(retainedTail, true);
|
|
649
|
+
return exchanges;
|
|
650
|
+
};
|
|
651
|
+
var dialogueExcerpts = (exchange) => {
|
|
652
|
+
const heading = (role, message) => `${role} [entry ${message.entryId}${message.retained ? "; retained raw" : ""}]:`;
|
|
653
|
+
const userHeading = heading("User instruction", exchange.user);
|
|
654
|
+
const assistantHeading = exchange.assistant ? heading("Historical assistant response (not a verified outcome)", exchange.assistant) : "";
|
|
655
|
+
const available = Math.max(0, MAX_EXCHANGE_BYTES - utf8Bytes(userHeading + assistantHeading) - 8);
|
|
656
|
+
const userText = exchange.user.retained ? "" : exchange.user.text;
|
|
657
|
+
const assistantBytes = exchange.assistant && !exchange.assistant.retained ? utf8Bytes(exchange.assistant.text) : 0;
|
|
658
|
+
const userBudget = exchange.assistant ? Math.max(available / 2, available - assistantBytes) : available;
|
|
659
|
+
const user = boundedExcerpt(userText, Math.floor(userBudget));
|
|
660
|
+
const excerpts = [{ heading: userHeading, ...user }];
|
|
661
|
+
if (exchange.assistant) {
|
|
662
|
+
const assistant = boundedExcerpt(
|
|
663
|
+
exchange.assistant.retained ? "" : exchange.assistant.text,
|
|
664
|
+
available - utf8Bytes(user.text)
|
|
665
|
+
);
|
|
666
|
+
excerpts.unshift({ heading: assistantHeading, ...assistant });
|
|
667
|
+
}
|
|
668
|
+
return excerpts;
|
|
669
|
+
};
|
|
670
|
+
var projectDialogue = (exchanges) => {
|
|
671
|
+
let omittedBytes = 0;
|
|
672
|
+
const lines = exchanges.map((exchange) => dialogueExcerpts(exchange).map((excerpt) => {
|
|
673
|
+
omittedBytes += excerpt.omittedBytes;
|
|
674
|
+
return `${excerpt.heading}
|
|
675
|
+
${excerpt.text}`;
|
|
676
|
+
}).join("\n\n"));
|
|
677
|
+
return { lines, omittedBytes };
|
|
678
|
+
};
|
|
679
|
+
|
|
618
680
|
// src/compaction/projections.ts
|
|
619
681
|
var MAX_LINE = 140;
|
|
620
682
|
var FILE_TOOLS = /* @__PURE__ */ new Set(["read", "edit", "write", "grep", "find", "ls"]);
|
|
621
683
|
var MODIFYING_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
622
|
-
var MAX_USER_GOAL_LINES = 3;
|
|
623
|
-
var MAX_USER_GOAL_LINE = 1024;
|
|
624
684
|
var MAX_USER_ONELINER = 120;
|
|
625
685
|
var MAX_EARLIER_USER = 80;
|
|
626
686
|
var MAX_STATUS_LINE = 140;
|
|
@@ -656,10 +716,6 @@ var customMessageLine = (event, maxText) => {
|
|
|
656
716
|
const visibility = event.display ? "visible" : "hidden";
|
|
657
717
|
return `custom ${quoted(event.customType, 80)} (${visibility}): ${quoted(event.text, maxText)}${customDetailsSuffix(event.details)}`;
|
|
658
718
|
};
|
|
659
|
-
var trailingEllipsis = (lines, max) => {
|
|
660
|
-
if (lines.length <= max) return lines;
|
|
661
|
-
return [...lines.slice(0, max), "\u2026"];
|
|
662
|
-
};
|
|
663
719
|
var pathOf = (args) => {
|
|
664
720
|
const value = args.path ?? args.file ?? args.dir;
|
|
665
721
|
return typeof value === "string" && value.trim() ? value : void 0;
|
|
@@ -745,27 +801,14 @@ var commonRoot = (paths) => {
|
|
|
745
801
|
return `${first.slice(0, common).join("/")}/`;
|
|
746
802
|
};
|
|
747
803
|
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;
|
|
804
|
+
var projectGoal = (events, protectedUsers) => {
|
|
805
|
+
const lines = [];
|
|
806
|
+
function* historicalUsers() {
|
|
759
807
|
for (const event of events) {
|
|
760
|
-
if (event.kind
|
|
761
|
-
if (!skippedFirst) {
|
|
762
|
-
skippedFirst = true;
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
yield event;
|
|
808
|
+
if (event.kind === "user" && !protectedUsers.has(event.entryId)) yield event;
|
|
766
809
|
}
|
|
767
810
|
}
|
|
768
|
-
const sampled = sampleAddressedFrom(
|
|
811
|
+
const sampled = sampleAddressedFrom(historicalUsers(), MAX_LATER_GOALS);
|
|
769
812
|
for (let index = 0; index < sampled.values.length; index++) {
|
|
770
813
|
if (sampled.omitted > 0 && index === sampled.splitIndex) {
|
|
771
814
|
lines.push(omissionLine(
|
|
@@ -1079,8 +1122,10 @@ var projectTranscript = (events) => {
|
|
|
1079
1122
|
}
|
|
1080
1123
|
return { lines, omitted };
|
|
1081
1124
|
};
|
|
1082
|
-
var projectWithMetadata = (events) => {
|
|
1083
|
-
const
|
|
1125
|
+
var projectWithMetadata = (events, retainedDialogue = []) => {
|
|
1126
|
+
const exchanges = recentDialogue(events, retainedDialogue);
|
|
1127
|
+
const dialogue = projectDialogue(exchanges);
|
|
1128
|
+
const goal = projectGoal(events, new Set(exchanges.map(({ user }) => user.entryId)));
|
|
1084
1129
|
const files = projectFiles(events);
|
|
1085
1130
|
const activity = projectActivity(events);
|
|
1086
1131
|
const outstanding = projectOutstandingWithMetadata(events);
|
|
@@ -1088,6 +1133,7 @@ var projectWithMetadata = (events) => {
|
|
|
1088
1133
|
const transcript = projectTranscript(events);
|
|
1089
1134
|
return {
|
|
1090
1135
|
sections: {
|
|
1136
|
+
dialogue: dialogue.lines,
|
|
1091
1137
|
goal: goal.lines,
|
|
1092
1138
|
files: files.lines,
|
|
1093
1139
|
activity: activity.lines,
|
|
@@ -1098,6 +1144,7 @@ var projectWithMetadata = (events) => {
|
|
|
1098
1144
|
},
|
|
1099
1145
|
omittedCounts: {
|
|
1100
1146
|
goal: goal.omitted,
|
|
1147
|
+
dialogueBytes: dialogue.omittedBytes,
|
|
1101
1148
|
files: files.omitted,
|
|
1102
1149
|
activity: activity.omitted,
|
|
1103
1150
|
outstanding: outstanding.omitted,
|
|
@@ -1108,8 +1155,9 @@ var projectWithMetadata = (events) => {
|
|
|
1108
1155
|
};
|
|
1109
1156
|
|
|
1110
1157
|
// src/compaction/render.ts
|
|
1111
|
-
var
|
|
1112
|
-
{ key: "
|
|
1158
|
+
var SUMMARY_SECTIONS = [
|
|
1159
|
+
{ key: "dialogue", header: "[Recent user directions and discussion]", maxBytes: 12288 },
|
|
1160
|
+
{ key: "goal", header: "[Historical requests]", maxBytes: 4096 },
|
|
1113
1161
|
{ key: "files", header: "[Files And Changes]", maxBytes: 4608 },
|
|
1114
1162
|
{ key: "activity", header: "[Fabric Activity]", maxBytes: 2048 },
|
|
1115
1163
|
{ key: "outstanding", header: "[Outstanding Context]", maxBytes: 4608 },
|
|
@@ -1142,42 +1190,89 @@ var boundedBlock = (header, sourceLines, maxBytes) => {
|
|
|
1142
1190
|
}
|
|
1143
1191
|
return clipUtf8(header, maxBytes);
|
|
1144
1192
|
};
|
|
1145
|
-
var
|
|
1193
|
+
var boundedHistory = (blocks, maxBytes) => {
|
|
1194
|
+
const candidates = blocks.map((block) => {
|
|
1195
|
+
const text = boundedBlock(block.header, block.lines, block.maxBytes);
|
|
1196
|
+
const bytes = utf8Bytes(text);
|
|
1197
|
+
const minimum2 = block.lines.length === 1 ? bytes : Math.min(bytes, utf8Bytes([block.header, ...sampledLines(block.lines, 0)].join("\n")));
|
|
1198
|
+
return { ...block, text, bytes, minimum: minimum2 };
|
|
1199
|
+
});
|
|
1200
|
+
const total = candidates.reduce((sum, block) => sum + block.bytes, 0);
|
|
1201
|
+
if (total <= maxBytes) return candidates.map(({ text }) => text);
|
|
1202
|
+
const minimum = candidates.reduce((sum, block) => sum + block.minimum, 0);
|
|
1203
|
+
let remaining = maxBytes - minimum;
|
|
1204
|
+
let demand = total - minimum;
|
|
1205
|
+
return candidates.map((block) => {
|
|
1206
|
+
const wanted = block.bytes - block.minimum;
|
|
1207
|
+
const extra = demand === 0 ? 0 : Math.min(wanted, Math.floor(remaining * wanted / demand));
|
|
1208
|
+
const text = boundedBlock(block.header, block.lines, block.minimum + extra);
|
|
1209
|
+
remaining -= utf8Bytes(text) - block.minimum;
|
|
1210
|
+
demand -= wanted;
|
|
1211
|
+
return text;
|
|
1212
|
+
});
|
|
1213
|
+
};
|
|
1214
|
+
var protectedBlock = (header, items, maxBytes) => {
|
|
1215
|
+
const text = [header, ...items].join("\n\n");
|
|
1216
|
+
if (utf8Bytes(text) <= maxBytes) return { text, omittedBytes: 0 };
|
|
1217
|
+
let remaining = Math.max(0, maxBytes - utf8Bytes(header) - 2 * items.length);
|
|
1218
|
+
const share = Math.floor(remaining / items.length);
|
|
1219
|
+
const budgets = items.map((item) => Math.min(utf8Bytes(item), share));
|
|
1220
|
+
remaining -= budgets.reduce((sum, bytes) => sum + bytes, 0);
|
|
1221
|
+
let omittedBytes = 0;
|
|
1222
|
+
const excerpts = items.map((item, index) => {
|
|
1223
|
+
const extra = Math.min(remaining, utf8Bytes(item) - budgets[index]);
|
|
1224
|
+
remaining -= extra;
|
|
1225
|
+
const excerpt = boundedExcerpt(item, budgets[index] + extra);
|
|
1226
|
+
omittedBytes += excerpt.omittedBytes;
|
|
1227
|
+
return excerpt.text;
|
|
1228
|
+
});
|
|
1229
|
+
return { text: [header, ...excerpts].join("\n\n"), omittedBytes };
|
|
1230
|
+
};
|
|
1231
|
+
var renderSummaryWithMetadata = (sections, options) => {
|
|
1146
1232
|
const blocks = [];
|
|
1147
|
-
|
|
1233
|
+
const history = [];
|
|
1234
|
+
let requestOmittedBytes = 0;
|
|
1235
|
+
let dialogueOmittedBytes = 0;
|
|
1236
|
+
const request = () => {
|
|
1237
|
+
if (!options.requestLines?.length) return;
|
|
1238
|
+
const rendered = protectedBlock("[Compaction Request]", options.requestLines, REQUEST_MAX_BYTES);
|
|
1239
|
+
blocks.push(rendered.text);
|
|
1240
|
+
requestOmittedBytes = rendered.omittedBytes;
|
|
1241
|
+
};
|
|
1242
|
+
for (const { key, header, maxBytes } of SUMMARY_SECTIONS) {
|
|
1148
1243
|
const lines = sections[key];
|
|
1149
|
-
if (
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1244
|
+
if (key === "dialogue") {
|
|
1245
|
+
if (lines.length > 0) {
|
|
1246
|
+
const rendered = protectedBlock(header, lines, maxBytes);
|
|
1247
|
+
blocks.push(rendered.text);
|
|
1248
|
+
dialogueOmittedBytes = rendered.omittedBytes;
|
|
1249
|
+
}
|
|
1250
|
+
request();
|
|
1251
|
+
} else if (lines.length > 0) {
|
|
1252
|
+
history.push({ header, lines, maxBytes });
|
|
1153
1253
|
}
|
|
1154
1254
|
}
|
|
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
1255
|
if (sections.transcript.length > 0) {
|
|
1159
|
-
|
|
1256
|
+
history.push({ header: "---", lines: sections.transcript, maxBytes: TRANSCRIPT_MAX_BYTES });
|
|
1160
1257
|
}
|
|
1161
1258
|
const timestamp = options.lastTimestamp || "(unknown time)";
|
|
1162
1259
|
const range = options.firstEntryId || options.lastEntryId ? `${options.firstEntryId || "(start)"} \u2192 ${options.lastEntryId || "(end)"}` : "(no entries)";
|
|
1163
1260
|
const footer = options.summaryKind === "branch" ? `[branch summarized ${timestamp}; structural source entries ${range}]` : `[compacted ${timestamp}; cumulative source entries ${range}]`;
|
|
1164
|
-
|
|
1261
|
+
const footerBlock = boundedBlock("---", [footer, POINTER_LINE], FOOTER_MAX_BYTES);
|
|
1262
|
+
const framingBytes = utf8Bytes(footerBlock) + 2 * (blocks.length + history.length) + 1;
|
|
1263
|
+
const protectedBytes = blocks.reduce((sum, block) => sum + utf8Bytes(block), 0);
|
|
1264
|
+
blocks.push(...boundedHistory(history, MAX_SUMMARY_BYTES - framingBytes - protectedBytes), footerBlock);
|
|
1165
1265
|
const summary = `${blocks.join("\n\n")}
|
|
1166
1266
|
`;
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1267
|
+
return {
|
|
1268
|
+
summary: utf8Bytes(summary) <= MAX_SUMMARY_BYTES ? summary : `${clipUtf8(summary, MAX_SUMMARY_BYTES - 1, "")}
|
|
1269
|
+
`,
|
|
1270
|
+
requestOmittedBytes,
|
|
1271
|
+
dialogueOmittedBytes
|
|
1272
|
+
};
|
|
1170
1273
|
};
|
|
1171
1274
|
|
|
1172
1275
|
// 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
1276
|
var asJsonObject = (value) => {
|
|
1182
1277
|
try {
|
|
1183
1278
|
const cloned = JSON.parse(JSON.stringify(value));
|
|
@@ -1331,22 +1426,24 @@ var compileFabricBranchSummary = (entriesToSummarize, customInstructions, enrich
|
|
|
1331
1426
|
if (events.length === 0) return void 0;
|
|
1332
1427
|
const projected = projectWithMetadata(events);
|
|
1333
1428
|
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, {
|
|
1429
|
+
const sections = SUMMARY_SECTIONS.filter(({ key }) => projected.sections[key].length > 0).map(({ header }) => header);
|
|
1430
|
+
if (instructions.requestLines.length > 0) {
|
|
1431
|
+
sections.splice(projected.sections.dialogue.length > 0 ? 1 : 0, 0, "[Compaction Request]");
|
|
1432
|
+
}
|
|
1433
|
+
const rendered = renderSummaryWithMetadata(projected.sections, {
|
|
1342
1434
|
firstEntryId: entriesToSummarize[0]?.id ?? "",
|
|
1343
1435
|
lastEntryId: entriesToSummarize.at(-1)?.id ?? "",
|
|
1344
1436
|
lastTimestamp: entriesToSummarize.at(-1)?.timestamp ?? "",
|
|
1345
1437
|
...instructions.requestLines.length > 0 ? { requestLines: instructions.requestLines } : {},
|
|
1346
1438
|
summaryKind: "branch"
|
|
1347
1439
|
});
|
|
1440
|
+
const request = {
|
|
1441
|
+
text: instructions.requestLines.join("\n"),
|
|
1442
|
+
sourceBytes: instructions.policy.sourceBytes,
|
|
1443
|
+
truncated: instructions.policy.truncated || rendered.requestOmittedBytes > 0
|
|
1444
|
+
};
|
|
1348
1445
|
return {
|
|
1349
|
-
summary,
|
|
1446
|
+
summary: rendered.summary,
|
|
1350
1447
|
details: boundedDetails(entriesToSummarize, factsFromEvents(events), sections, request, oldLeafId)
|
|
1351
1448
|
};
|
|
1352
1449
|
};
|
|
@@ -1529,18 +1626,15 @@ var tokenCalibration = (branchEntries, tokensBefore, rawTokensBefore) => {
|
|
|
1529
1626
|
);
|
|
1530
1627
|
return { tokenScale, fixedOverheadTokens };
|
|
1531
1628
|
};
|
|
1629
|
+
var continuityTailLimit = (value) => value !== void 0 && Number.isSafeInteger(value) && value >= 0 ? value : DEFAULT_COMPACTION_SETTINGS.keepRecentTokens;
|
|
1532
1630
|
var continuityCutPlan = (branchEntries, tokensBefore, budget) => {
|
|
1533
|
-
if (!Number.isFinite(budget.contextWindow) || budget.contextWindow <= 0) return void 0;
|
|
1631
|
+
if (typeof budget.contextWindow !== "number" || !Number.isFinite(budget.contextWindow) || budget.contextWindow <= 0 || typeof budget.targetContextRatio !== "number" || !Number.isFinite(budget.targetContextRatio)) return void 0;
|
|
1534
1632
|
const contextWindow = Math.floor(budget.contextWindow);
|
|
1535
1633
|
const reserveTokens = Math.max(0, Math.floor(budget.reserveTokens));
|
|
1536
|
-
const keepRecentTokens =
|
|
1634
|
+
const keepRecentTokens = continuityTailLimit(budget.keepRecentTokens);
|
|
1537
1635
|
const targetContextRatio = Math.max(0.25, Math.min(0.85, budget.targetContextRatio));
|
|
1538
1636
|
const rawTokensBefore = rawContextTokens(branchEntries);
|
|
1539
|
-
const { tokenScale, fixedOverheadTokens } = tokenCalibration(
|
|
1540
|
-
branchEntries,
|
|
1541
|
-
tokensBefore,
|
|
1542
|
-
rawTokensBefore
|
|
1543
|
-
);
|
|
1637
|
+
const { tokenScale, fixedOverheadTokens } = budget.calibrateUsage === false ? { tokenScale: 1, fixedOverheadTokens: 0 } : tokenCalibration(branchEntries, tokensBefore, rawTokensBefore);
|
|
1544
1638
|
const continuityTargetTokens = Math.max(1, Math.ceil(
|
|
1545
1639
|
fixedOverheadTokens + (keepRecentTokens + SUMMARY_RAW_TOKEN_BUDGET) * tokenScale
|
|
1546
1640
|
));
|
|
@@ -1593,7 +1687,7 @@ var boundary = (summarized, firstKeptEntryId, budget) => {
|
|
|
1593
1687
|
...budget ? { budget } : {}
|
|
1594
1688
|
};
|
|
1595
1689
|
};
|
|
1596
|
-
var computeContinuityCut = (branchEntries, live, plan) => {
|
|
1690
|
+
var computeContinuityCut = (branchEntries, live, plan, rawTailTokenBudget = plan?.rawTailTokenBudget ?? DEFAULT_COMPACTION_SETTINGS.keepRecentTokens) => {
|
|
1597
1691
|
const suffixTokens = new Array(live.length + 1).fill(0);
|
|
1598
1692
|
for (let index = live.length - 1; index >= 0; index--) {
|
|
1599
1693
|
suffixTokens[index] = suffixTokens[index + 1] + live[index].estimatedTokens;
|
|
@@ -1604,13 +1698,13 @@ var computeContinuityCut = (branchEntries, live, plan) => {
|
|
|
1604
1698
|
for (let index = 1; index < live.length; index++) {
|
|
1605
1699
|
const item = live[index];
|
|
1606
1700
|
if (item.branchIndex <= previousCompactionIndex) continue;
|
|
1607
|
-
if (!item.cutPoint || suffixTokens[index] >
|
|
1701
|
+
if (!item.cutPoint || suffixTokens[index] > rawTailTokenBudget) continue;
|
|
1608
1702
|
if (!closureSafe(spans, item.branchIndex)) continue;
|
|
1609
1703
|
cutIndex = index;
|
|
1610
1704
|
break;
|
|
1611
1705
|
}
|
|
1612
1706
|
const retainedRawTokens = suffixTokens[cutIndex] ?? 0;
|
|
1613
|
-
const details = {
|
|
1707
|
+
const details = plan ? {
|
|
1614
1708
|
strategy: "continuity",
|
|
1615
1709
|
contextWindow: plan.contextWindow,
|
|
1616
1710
|
targetContextRatio: plan.targetContextRatio,
|
|
@@ -1627,7 +1721,7 @@ var computeContinuityCut = (branchEntries, live, plan) => {
|
|
|
1627
1721
|
reductionCeilingTokens: plan.reductionCeilingTokens,
|
|
1628
1722
|
rawTailTokenBudget: plan.rawTailTokenBudget,
|
|
1629
1723
|
bindingConstraint: plan.bindingConstraint
|
|
1630
|
-
};
|
|
1724
|
+
} : void 0;
|
|
1631
1725
|
if (cutIndex >= live.length) {
|
|
1632
1726
|
return boundary(live.map((item) => item.entry), "", details);
|
|
1633
1727
|
}
|
|
@@ -1637,7 +1731,7 @@ var computeContinuityCut = (branchEntries, live, plan) => {
|
|
|
1637
1731
|
details
|
|
1638
1732
|
);
|
|
1639
1733
|
};
|
|
1640
|
-
var
|
|
1734
|
+
var proposeCut = (branchEntries, options) => {
|
|
1641
1735
|
const live = collectLive(branchEntries);
|
|
1642
1736
|
if (live.length === 0) return { ok: false, reason: "empty" };
|
|
1643
1737
|
if (options) {
|
|
@@ -1645,8 +1739,12 @@ var computeCut = (branchEntries, options) => {
|
|
|
1645
1739
|
if (plan) return computeContinuityCut(branchEntries, live, plan);
|
|
1646
1740
|
}
|
|
1647
1741
|
const lastBoundary = lastBoundaryIndex(live);
|
|
1648
|
-
|
|
1649
|
-
const
|
|
1742
|
+
const closed = lastBoundary > 0 ? closeCut(branchEntries, live, lastBoundary) : 0;
|
|
1743
|
+
const keepRecentTokens = continuityTailLimit(options?.budget.keepRecentTokens);
|
|
1744
|
+
const tailTokens = live.slice(closed).reduce((sum, item) => sum + item.estimatedTokens, 0);
|
|
1745
|
+
if (tailTokens > keepRecentTokens) {
|
|
1746
|
+
return computeContinuityCut(branchEntries, live, void 0, keepRecentTokens);
|
|
1747
|
+
}
|
|
1650
1748
|
const previousCompactionIndex = findLastCompaction(branchEntries)?.index ?? -1;
|
|
1651
1749
|
if (closed <= 0 || live[closed].branchIndex <= previousCompactionIndex) {
|
|
1652
1750
|
return boundary(live.map((item) => item.entry), "");
|
|
@@ -1656,6 +1754,24 @@ var computeCut = (branchEntries, options) => {
|
|
|
1656
1754
|
live[closed].entry.id
|
|
1657
1755
|
);
|
|
1658
1756
|
};
|
|
1757
|
+
var computeCut = (branchEntries, options) => {
|
|
1758
|
+
const proposed = proposeCut(branchEntries, options);
|
|
1759
|
+
if (!proposed.ok) return proposed;
|
|
1760
|
+
const live = collectLive(branchEntries);
|
|
1761
|
+
const kept = proposed.firstKeptEntryId ? live.findIndex((item) => item.entry.id === proposed.firstKeptEntryId) : live.length;
|
|
1762
|
+
if (kept < 0) return { ok: false, reason: "empty" };
|
|
1763
|
+
const boundaryIndex = live[kept]?.branchIndex ?? branchEntries.length;
|
|
1764
|
+
const retained = live.slice(kept).reduce((sum, item) => sum + item.estimatedTokens, 0);
|
|
1765
|
+
const budget = proposed.budget?.rawTailTokenBudget ?? continuityTailLimit(options?.budget.keepRecentTokens);
|
|
1766
|
+
if (!acceptCompactionCut({
|
|
1767
|
+
eligible: kept === live.length || live[kept].cutPoint,
|
|
1768
|
+
afterPrevious: boundaryIndex > (findLastCompaction(branchEntries)?.index ?? -1),
|
|
1769
|
+
retained,
|
|
1770
|
+
budget,
|
|
1771
|
+
boundary: boundaryIndex
|
|
1772
|
+
}, callResultSpans(branchEntries).values())) return { ok: false, reason: "empty" };
|
|
1773
|
+
return proposed;
|
|
1774
|
+
};
|
|
1659
1775
|
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1660
1776
|
var isEntryRange = (value) => isRecord(value) && typeof value.first === "string" && typeof value.last === "string";
|
|
1661
1777
|
var isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
@@ -1708,7 +1824,7 @@ var isFabricV2Details = (value) => {
|
|
|
1708
1824
|
"earlierTurns",
|
|
1709
1825
|
"transcript",
|
|
1710
1826
|
"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, [
|
|
1827
|
+
]) && (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
1828
|
"sourceBytes",
|
|
1713
1829
|
"preserveCount",
|
|
1714
1830
|
"omittedPreserveCount"
|
|
@@ -1764,28 +1880,37 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1764
1880
|
if (!cut.ok) return { cancel: true, reason: "fabric: nothing to compact" };
|
|
1765
1881
|
const source = cumulativeSource(branchEntries, cut.firstKeptEntryId);
|
|
1766
1882
|
if (source.events.length === 0) return { cancel: true, reason: "fabric: no raw cumulative source" };
|
|
1767
|
-
const
|
|
1883
|
+
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") : [];
|
|
1884
|
+
const projected = projectWithMetadata(source.events, retainedDialogue);
|
|
1768
1885
|
const sections = projected.sections;
|
|
1769
1886
|
runEnrichers(enrichers, source.events, sections);
|
|
1770
|
-
const
|
|
1887
|
+
const rendered = renderSummaryWithMetadata(sections, {
|
|
1771
1888
|
firstEntryId: source.range.first,
|
|
1772
1889
|
lastEntryId: source.range.last,
|
|
1773
1890
|
lastTimestamp: source.timestamp,
|
|
1774
1891
|
requestLines: instructions.requestLines
|
|
1775
1892
|
});
|
|
1893
|
+
const { summary } = rendered;
|
|
1776
1894
|
const projectedTokensAfter = cut.budget ? Math.ceil(
|
|
1777
1895
|
cut.budget.fixedOverheadTokens + (cut.budget.retainedRawTokens + Math.ceil(summary.length / 4)) * cut.budget.tokenScale
|
|
1778
1896
|
) : void 0;
|
|
1779
1897
|
const budgetDetails = cut.budget && projectedTokensAfter !== void 0 ? { ...cut.budget, projectedTokensAfter } : void 0;
|
|
1780
|
-
if (
|
|
1898
|
+
if (!acceptSummaryBounds(
|
|
1899
|
+
utf8Bytes(summary),
|
|
1900
|
+
MAX_SUMMARY_BYTES,
|
|
1901
|
+
budgetDetails?.projectedTokensAfter ?? 0,
|
|
1902
|
+
budgetDetails?.targetContextTokens ?? 0
|
|
1903
|
+
)) {
|
|
1781
1904
|
return {
|
|
1782
1905
|
cancel: true,
|
|
1783
1906
|
reason: "fabric: no deterministic summary fits the continuity context target"
|
|
1784
1907
|
};
|
|
1785
1908
|
}
|
|
1786
1909
|
const versions = priorFabricVersions(branchEntries);
|
|
1787
|
-
const sectionHeaders =
|
|
1788
|
-
if (instructions.requestLines.length > 0)
|
|
1910
|
+
const sectionHeaders = SUMMARY_SECTIONS.filter(({ key }) => sections[key].length > 0).map(({ header }) => header);
|
|
1911
|
+
if (instructions.requestLines.length > 0) {
|
|
1912
|
+
sectionHeaders.splice(sections.dialogue.length > 0 ? 1 : 0, 0, "[Compaction Request]");
|
|
1913
|
+
}
|
|
1789
1914
|
const details = {
|
|
1790
1915
|
compactor: "fabric",
|
|
1791
1916
|
version: 2,
|
|
@@ -1807,13 +1932,18 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1807
1932
|
},
|
|
1808
1933
|
omittedCounts: {
|
|
1809
1934
|
...projected.omittedCounts,
|
|
1935
|
+
dialogueBytes: (projected.omittedCounts.dialogueBytes ?? 0) + rendered.dialogueOmittedBytes,
|
|
1810
1936
|
preserve: instructions.policy.omittedPreserveCount,
|
|
1811
1937
|
// Thinking parts never survive normalization into a rendered summary;
|
|
1812
1938
|
// the structural count keeps that erasure auditable against the raw
|
|
1813
1939
|
// prefix instead of letting deliberation vanish untracked.
|
|
1814
1940
|
thinking: countErasedThinkingBlocks(source.prefixEntries)
|
|
1815
1941
|
},
|
|
1816
|
-
instructionPolicy:
|
|
1942
|
+
instructionPolicy: {
|
|
1943
|
+
...instructions.policy,
|
|
1944
|
+
truncated: instructions.policy.truncated || rendered.requestOmittedBytes > 0,
|
|
1945
|
+
renderedOmittedBytes: rendered.requestOmittedBytes
|
|
1946
|
+
},
|
|
1817
1947
|
stableAddresses: {
|
|
1818
1948
|
firstKeptEntryId: cut.firstKeptEntryId,
|
|
1819
1949
|
cumulativeSourceRange: source.range,
|
|
@@ -1831,14 +1961,6 @@ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_
|
|
|
1831
1961
|
}
|
|
1832
1962
|
};
|
|
1833
1963
|
};
|
|
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
1964
|
var notifyInstructionError = (context, error) => {
|
|
1843
1965
|
if (!context?.hasUI) return;
|
|
1844
1966
|
context.ui.notify(clipUtf8(`Fabric compaction rejected: ${error.code}: ${error.message}`, 512), "error");
|
|
@@ -1864,12 +1986,12 @@ var registerCompactionHook = (pi, options) => {
|
|
|
1864
1986
|
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
1987
|
const advertisedWindow = typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? contextWindow : void 0;
|
|
1866
1988
|
const effectiveWindow = evidenceWindow === void 0 ? advertisedWindow : advertisedWindow === void 0 ? evidenceWindow : Math.min(advertisedWindow, evidenceWindow);
|
|
1867
|
-
const budget =
|
|
1868
|
-
contextWindow: effectiveWindow,
|
|
1869
|
-
targetContextRatio,
|
|
1989
|
+
const budget = {
|
|
1990
|
+
...effectiveWindow !== void 0 ? { contextWindow: effectiveWindow } : {},
|
|
1991
|
+
...typeof targetContextRatio === "number" && Number.isFinite(targetContextRatio) ? { targetContextRatio } : {},
|
|
1870
1992
|
reserveTokens: settings.reserveTokens,
|
|
1871
1993
|
keepRecentTokens: settings.keepRecentTokens
|
|
1872
|
-
}
|
|
1994
|
+
};
|
|
1873
1995
|
const result = compileFabricSummary(
|
|
1874
1996
|
branchEntries ?? [],
|
|
1875
1997
|
preparation.tokensBefore,
|
|
@@ -1921,4 +2043,4 @@ export {
|
|
|
1921
2043
|
compileFabricSummary,
|
|
1922
2044
|
registerCompactionHook
|
|
1923
2045
|
};
|
|
1924
|
-
//# sourceMappingURL=chunk-
|
|
2046
|
+
//# sourceMappingURL=chunk-Q5BMTL6A.js.map
|