@yishiguji/tokenarena 0.16.1 → 0.16.2
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/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -626,16 +626,22 @@ function readRollout(path) {
|
|
|
626
626
|
let rootMeta = null;
|
|
627
627
|
let model = "unknown";
|
|
628
628
|
let latestTimestampOrder = 0n;
|
|
629
|
+
let minLineTimestampOrder = null;
|
|
629
630
|
let line = 0;
|
|
631
|
+
let lineCount = 0;
|
|
630
632
|
for (const text of content.split("\n")) {
|
|
631
633
|
line++;
|
|
632
634
|
if (!text.trim()) continue;
|
|
635
|
+
lineCount++;
|
|
633
636
|
try {
|
|
634
637
|
const event = JSON.parse(text);
|
|
635
638
|
const timestamp = readTimestamp(event.timestamp);
|
|
636
639
|
const order = timestampOrder(event.timestamp, timestamp);
|
|
637
|
-
if (order !== null
|
|
638
|
-
latestTimestampOrder = order;
|
|
640
|
+
if (order !== null) {
|
|
641
|
+
if (order > latestTimestampOrder) latestTimestampOrder = order;
|
|
642
|
+
if (minLineTimestampOrder === null || order < minLineTimestampOrder)
|
|
643
|
+
minLineTimestampOrder = order;
|
|
644
|
+
}
|
|
639
645
|
if (event.type === "session_meta" && !rootMeta) rootMeta = event;
|
|
640
646
|
if (event.type === "turn_context") {
|
|
641
647
|
model = readId(event.payload?.model) || readId(event.payload?.info?.model) || model;
|
|
@@ -678,11 +684,14 @@ function readRollout(path) {
|
|
|
678
684
|
parentConflict: Boolean(
|
|
679
685
|
forkedFrom && spawnedFrom && forkedFrom !== spawnedFrom
|
|
680
686
|
),
|
|
687
|
+
forkOrdinalExclusive: typeof meta?.forked_from_ordinal_exclusive === "number" && Number.isSafeInteger(meta.forked_from_ordinal_exclusive) && meta.forked_from_ordinal_exclusive > 0 ? meta.forked_from_ordinal_exclusive : null,
|
|
688
|
+
lineCount,
|
|
681
689
|
rootTimestampOrder: timestampOrder(
|
|
682
690
|
rootMeta?.timestamp,
|
|
683
691
|
readTimestamp(rootMeta?.timestamp)
|
|
684
692
|
),
|
|
685
693
|
latestTimestampOrder,
|
|
694
|
+
minLineTimestampOrder,
|
|
686
695
|
tokens,
|
|
687
696
|
prompts
|
|
688
697
|
};
|
|
@@ -743,6 +752,7 @@ var CodexParser = class {
|
|
|
743
752
|
files: [],
|
|
744
753
|
timeline: [],
|
|
745
754
|
latestTimestampOrder: 0n,
|
|
755
|
+
minLineTimestampOrder: null,
|
|
746
756
|
invalidTokenTimestamp: false,
|
|
747
757
|
status: "new"
|
|
748
758
|
};
|
|
@@ -751,6 +761,8 @@ var CodexParser = class {
|
|
|
751
761
|
thread.files.push(file);
|
|
752
762
|
if (file.latestTimestampOrder > thread.latestTimestampOrder)
|
|
753
763
|
thread.latestTimestampOrder = file.latestTimestampOrder;
|
|
764
|
+
if (file.minLineTimestampOrder !== null && (thread.minLineTimestampOrder === null || file.minLineTimestampOrder < thread.minLineTimestampOrder))
|
|
765
|
+
thread.minLineTimestampOrder = file.minLineTimestampOrder;
|
|
754
766
|
thread.invalidTokenTimestamp ||= file.tokens.some(
|
|
755
767
|
(token) => !token.timestamp
|
|
756
768
|
);
|
|
@@ -776,7 +788,16 @@ var CodexParser = class {
|
|
|
776
788
|
if (file.parentConflict || file.parentId) {
|
|
777
789
|
const parent = file.parentId ? threadIndex.get(file.parentId) : void 0;
|
|
778
790
|
const cutoff = file.rootTimestampOrder;
|
|
779
|
-
|
|
791
|
+
const coverageOk = parent ? file.forkOrdinalExclusive !== null ? (
|
|
792
|
+
// 多文件父线程按最新文件(通常就是产生该 fork 的 rollout)
|
|
793
|
+
// 的行数核验;其余文件属于同一线程的历史分段。
|
|
794
|
+
parent.files.some(
|
|
795
|
+
(rollout) => rollout.lineCount >= (file.forkOrdinalExclusive ?? 0)
|
|
796
|
+
)
|
|
797
|
+
) : cutoff !== null && // 父最大时间戳落后不超过 1 秒,或父内容完全早于截止点
|
|
798
|
+
// 且父最早行时间戳也早于截止点(父在截止前已停止写入)。
|
|
799
|
+
(parent.latestTimestampOrder >= cutoff - 1000000n || parent.minLineTimestampOrder !== null && parent.minLineTimestampOrder < cutoff) : false;
|
|
800
|
+
if (file.parentConflict || !parent || parent === thread || cutoff === null || !processThread(parent) || parent.invalidTokenTimestamp || !coverageOk) {
|
|
780
801
|
logger.warn(
|
|
781
802
|
"Codex fork replay could not be verified; skipping " + basename2(file.path)
|
|
782
803
|
);
|