@niracler/encore 0.4.0 → 0.4.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/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/package.json +2 -1
- package/player/encore-player.css +2 -5
- package/player/encore-player.js +149 -113
- package/schema/session.schema.json +9 -1
- package/src/antigravity-context.mjs +122 -0
- package/src/antigravity-context.proto +43 -0
- package/src/antigravity.mjs +23 -25
- package/src/common.mjs +2 -2
- package/src/i18n.mjs +8 -6
- package/src/index.d.ts +3 -0
- package/src/index.mjs +1 -1
- package/src/player-runtime.mjs +15 -8
- package/src/render.mjs +19 -17
- package/src/session-picker.mjs +2 -1
- package/src/timeline.mjs +106 -81
package/src/timeline.mjs
CHANGED
|
@@ -17,6 +17,7 @@ function resolveWindowCapacity(tool = 'codex', model = '', contextWindow = 0) {
|
|
|
17
17
|
return { tokens: contextWindow, label }
|
|
18
18
|
}
|
|
19
19
|
const t = String(tool || '').toLowerCase()
|
|
20
|
+
if (t.startsWith('antigravity')) return { tokens: null, label: null }
|
|
20
21
|
const m = String(model || '').toLowerCase()
|
|
21
22
|
if (
|
|
22
23
|
t.startsWith('claude') ||
|
|
@@ -449,7 +450,7 @@ function assignFramesToGroups(rawGroups, frames = [], t) {
|
|
|
449
450
|
}
|
|
450
451
|
|
|
451
452
|
function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames = [], sessionStart = '', sessionMeta = {}, t) {
|
|
452
|
-
|
|
453
|
+
let windowSpec = resolveWindowCapacity(sessionTool, sessionModel, sessionMeta.contextWindow)
|
|
453
454
|
const initCtx = sessionMeta.initialContext || {}
|
|
454
455
|
const rawGroups = []
|
|
455
456
|
let work = []
|
|
@@ -480,14 +481,14 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
480
481
|
id: rec.id,
|
|
481
482
|
tag: rec.tag || '',
|
|
482
483
|
title: rec.title,
|
|
483
|
-
meta: rec.meta,
|
|
484
|
+
meta: observedOnly && rec.stepIndex >= 0 ? undefined : rec.meta,
|
|
484
485
|
payload: rec.payload,
|
|
485
486
|
...(rec.images?.length ? { images: rec.images } : {}),
|
|
486
487
|
}
|
|
487
488
|
return entry
|
|
488
489
|
}
|
|
489
490
|
|
|
490
|
-
// Antigravity
|
|
491
|
+
// Antigravity metadata may contain only part of the mounted context.
|
|
491
492
|
const observedOnly = sessionTool.startsWith('antigravity')
|
|
492
493
|
function initialRecords(key, defaults) {
|
|
493
494
|
const records = initCtx[key] || []
|
|
@@ -505,7 +506,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
505
506
|
const msgRecords = []
|
|
506
507
|
const memRecords = initialRecords('mem', defaultInjectedContext)
|
|
507
508
|
|
|
508
|
-
const sumTokEst = list => list.reduce((acc, r) => acc + (r.tokEst
|
|
509
|
+
const sumTokEst = list => list.reduce((acc, r) => acc + (r.tokEst ?? (observedOnly ? 0 : 600)), 0)
|
|
509
510
|
const sysTokens = sumTokEst(sysRecords)
|
|
510
511
|
let schemaTokens = sumTokEst(schemaRecords)
|
|
511
512
|
let userTokens = 0
|
|
@@ -535,7 +536,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
535
536
|
let dUser = userTokens
|
|
536
537
|
let dMsg = msgTokens
|
|
537
538
|
let dTool = toolTokens
|
|
538
|
-
if (lastRealTotal > 0) {
|
|
539
|
+
if (lastRealTotal > 0 && !observedOnly) {
|
|
539
540
|
const target = lastRealTotal + uncalibratedDelta
|
|
540
541
|
const fixed = dSys + dSchema + dMem + dSkill
|
|
541
542
|
const dyn = dUser + dMsg + dTool
|
|
@@ -558,6 +559,11 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
558
559
|
return { sys: dSys, schema: dSchema, user: dUser, mem: dMem, skill: dSkill, msg: dMsg, tool: dTool }
|
|
559
560
|
}
|
|
560
561
|
|
|
562
|
+
function reportedBuckets(disp, recorded) {
|
|
563
|
+
if (!observedOnly) return disp
|
|
564
|
+
return Object.fromEntries(Object.keys(disp).map(key => [key, recorded?.[key] ?? null]))
|
|
565
|
+
}
|
|
566
|
+
|
|
561
567
|
const assembleCategoryList = (stepIdx, countsBefore, toksBefore, disp) => {
|
|
562
568
|
const curTotal = disp.sys + disp.schema + disp.user + disp.mem + disp.msg + disp.tool + disp.skill
|
|
563
569
|
const kindPct = value => Math.round((value / Math.max(1, curTotal)) * 100)
|
|
@@ -582,10 +588,10 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
582
588
|
color,
|
|
583
589
|
itemCount: records.length,
|
|
584
590
|
count: t('itemCount', { n: records.length }),
|
|
585
|
-
tok: `≈${(curTok / 1000).toFixed(1)}k`,
|
|
586
|
-
pct: `${kindPct(curTok)}%`,
|
|
591
|
+
tok: curTok == null ? t('notRecorded') : `≈${(curTok / 1000).toFixed(1)}k`,
|
|
592
|
+
pct: observedOnly || curTok == null ? '' : `${kindPct(curTok)}%`,
|
|
587
593
|
delta: stepIdx >= 0 ? fmtCountDelta(records.length, prevCount) : '',
|
|
588
|
-
tokDelta: stepIdx >= 0 ? fmtTokDelta(curTok, prevTok) : '',
|
|
594
|
+
tokDelta: stepIdx >= 0 && !observedOnly ? fmtTokDelta(curTok, prevTok) : '',
|
|
589
595
|
itemIds,
|
|
590
596
|
newIds,
|
|
591
597
|
items: itemIds.map(rid => ({ ...contextRecords[rid], isNew: newSet.has(rid) })),
|
|
@@ -604,9 +610,15 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
604
610
|
|
|
605
611
|
let prevDisp = computeDisplayBuckets()
|
|
606
612
|
const initTotal = prevDisp.sys + prevDisp.schema + prevDisp.user + prevDisp.mem + prevDisp.skill + prevDisp.msg + prevDisp.tool
|
|
607
|
-
|
|
608
|
-
const
|
|
613
|
+
let observedUsage = initCtx.estimatedTokens ?? null
|
|
614
|
+
const openingTokens = observedOnly ? observedUsage : initTotal
|
|
615
|
+
const initCap = observedOnly ? windowSpec.tokens : Math.max(windowSpec.tokens, Math.ceil(initTotal * 1.25))
|
|
616
|
+
const initCapPct = val => (!initCap || val <= 0 ? 0 : Number((Math.max(0.4, (val / initCap) * 100)).toFixed(2)))
|
|
609
617
|
const initKindPct = val => Math.round((val / Math.max(1, initTotal)) * 100)
|
|
618
|
+
const openingByKind = Object.fromEntries(Object.entries(initCtx)
|
|
619
|
+
.filter(([, records]) => Array.isArray(records) && records.some(record => record.tokEst != null))
|
|
620
|
+
.map(([key, records]) => [key, sumTokEst(records)]))
|
|
621
|
+
const initialBuckets = reportedBuckets(prevDisp, openingByKind)
|
|
610
622
|
const zeroCounts = {
|
|
611
623
|
sys: sysRecords.length,
|
|
612
624
|
schema: schemaRecords.length,
|
|
@@ -617,12 +629,13 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
617
629
|
tool: 0,
|
|
618
630
|
}
|
|
619
631
|
const initialSnapshot = {
|
|
620
|
-
pct: Number(
|
|
632
|
+
pct: initCap && openingTokens != null ? Number(((openingTokens / initCap) * 100).toFixed(1)) : null,
|
|
621
633
|
windowTokens: windowSpec.tokens,
|
|
622
634
|
windowLabel: windowSpec.label,
|
|
623
|
-
totalTokens:
|
|
635
|
+
totalTokens: openingTokens,
|
|
636
|
+
...(observedOnly && openingTokens != null && { estimated: true }),
|
|
624
637
|
deltaTokens: 0,
|
|
625
|
-
segments: {
|
|
638
|
+
segments: observedOnly ? { used: initCap && openingTokens != null ? Math.min(openingTokens / initCap * 100, 100) : 0 } : {
|
|
626
639
|
sys: initCapPct(prevDisp.sys),
|
|
627
640
|
schema: initCapPct(prevDisp.schema),
|
|
628
641
|
user: 0,
|
|
@@ -631,7 +644,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
631
644
|
msg: 0,
|
|
632
645
|
tool: 0,
|
|
633
646
|
},
|
|
634
|
-
pctByKind: {
|
|
647
|
+
pctByKind: observedOnly ? {} : {
|
|
635
648
|
sys: initKindPct(prevDisp.sys),
|
|
636
649
|
schema: initKindPct(prevDisp.schema),
|
|
637
650
|
user: 0,
|
|
@@ -640,8 +653,8 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
640
653
|
msg: 0,
|
|
641
654
|
tool: 0,
|
|
642
655
|
},
|
|
643
|
-
tokensByKind:
|
|
644
|
-
categories: assembleCategoryList(-1, zeroCounts, prevDisp,
|
|
656
|
+
tokensByKind: initialBuckets,
|
|
657
|
+
categories: assembleCategoryList(-1, zeroCounts, prevDisp, initialBuckets),
|
|
645
658
|
}
|
|
646
659
|
|
|
647
660
|
const steps = rawGroups.map((group, index) => {
|
|
@@ -697,7 +710,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
697
710
|
payload: String(first.text || ''),
|
|
698
711
|
...(first.images?.length ? { images: first.images } : {}),
|
|
699
712
|
}))
|
|
700
|
-
for (const skill of extractSkillNames(first, knownSkillNames)) {
|
|
713
|
+
for (const skill of observedOnly ? [] : extractSkillNames(first, knownSkillNames)) {
|
|
701
714
|
if (!allSkills.includes(skill)) {
|
|
702
715
|
allSkills.push(skill)
|
|
703
716
|
const skTok = 1800
|
|
@@ -725,59 +738,68 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
725
738
|
} else if (group.groupType === 'compact') {
|
|
726
739
|
compactSeq++
|
|
727
740
|
const cItem = first
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
741
|
+
if (observedOnly) {
|
|
742
|
+
compactInfo = { seq: compactSeq, title: t('compactTitle', { seq: compactSeq }) }
|
|
743
|
+
if (cItem.text) {
|
|
744
|
+
compactInfo.content = cItem.text
|
|
745
|
+
compactInfo.docId = `compact-doc-${index}`
|
|
746
|
+
memRecords.push(registerRecord({ id: `compact-summary-${compactSeq}`, tag: 'Checkpoint',
|
|
747
|
+
title: compactInfo.title, payload: cItem.text, stepIndex: index }))
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
const preTokens = cItem.preTokens || prevTotal
|
|
751
|
+
const archivedTools = toolRecords.length
|
|
752
|
+
const postTokens = cItem.postTokens || Math.min(preTokens, Math.max(24000, Math.round(preTokens * 0.28)))
|
|
753
|
+
const droppedTokens = cItem.droppedTokens || Math.max(0, preTokens - postTokens)
|
|
754
|
+
const summaryText = String(cItem.text || cItem.summary || 'Context Compaction Summary').trim()
|
|
755
|
+
const sumTok = Math.max(1200, Math.round(summaryText.length * 0.35))
|
|
756
|
+
const docId = `compact-doc-${index}`
|
|
757
|
+
const recId = `compact-summary-${compactSeq}`
|
|
736
758
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
759
|
+
toolRecords = []
|
|
760
|
+
toolTokens = 0
|
|
761
|
+
userTokens = Math.round(userTokens * 0.35)
|
|
762
|
+
msgTokens = Math.round(msgTokens * 0.25)
|
|
763
|
+
memTokens += sumTok
|
|
764
|
+
lastRealTotal = postTokens
|
|
765
|
+
uncalibratedDelta = 0
|
|
766
|
+
const rawFixed = sysTokens + schemaTokens + memTokens + skillTokens
|
|
767
|
+
if (postTokens > 0 && rawFixed > postTokens * 0.85) {
|
|
768
|
+
mountScale = (postTokens * 0.72) / rawFixed
|
|
769
|
+
}
|
|
748
770
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
771
|
+
memRecords.push(registerRecord({
|
|
772
|
+
id: recId,
|
|
773
|
+
stepIndex: index,
|
|
774
|
+
tokEst: sumTok,
|
|
775
|
+
tag: 'Compact',
|
|
776
|
+
title: `${t('compactTitle', { seq: cItem.seq || compactSeq })} (${(preTokens / 1000).toFixed(1)}k → ${(postTokens / 1000).toFixed(1)}k)`,
|
|
777
|
+
meta: `-${(droppedTokens / 1000).toFixed(1)}k tok · ${stepTime}s`,
|
|
778
|
+
payload: summaryText,
|
|
779
|
+
}))
|
|
758
780
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
781
|
+
compactInfo = {
|
|
782
|
+
seq: cItem.seq || compactSeq,
|
|
783
|
+
trigger: cItem.trigger || 'auto',
|
|
784
|
+
preTokens,
|
|
785
|
+
postTokens,
|
|
786
|
+
droppedTokens,
|
|
787
|
+
archivedTools,
|
|
788
|
+
docId,
|
|
789
|
+
recId,
|
|
790
|
+
title: cItem.summary || t('compactTitle', { seq: cItem.seq || compactSeq }),
|
|
791
|
+
content: summaryText,
|
|
792
|
+
}
|
|
793
|
+
inBrief = `${(preTokens / 1000).toFixed(1)}k → ${(postTokens / 1000).toFixed(1)}k`
|
|
794
|
+
responseBrief = t('archivedTools', { n: archivedTools, tokens: (droppedTokens / 1000).toFixed(1) })
|
|
770
795
|
}
|
|
771
|
-
|
|
772
796
|
kind = 'compact'
|
|
773
797
|
primaryCat = 'mem'
|
|
774
798
|
speedLabel = '0.8×'
|
|
775
799
|
dwellMs = 2100
|
|
776
800
|
spotlight = 'context-compact'
|
|
777
801
|
detailTitle = t('compactTitle', { seq: compactInfo.seq })
|
|
778
|
-
detailSnippet =
|
|
779
|
-
inBrief = `${(preTokens / 1000).toFixed(1)}k → ${(postTokens / 1000).toFixed(1)}k`
|
|
780
|
-
responseBrief = t('archivedTools', { n: archivedTools, tokens: (droppedTokens / 1000).toFixed(1) })
|
|
802
|
+
detailSnippet = (compactInfo.content || '').slice(0, 260)
|
|
781
803
|
} else if (group.groupType === 'assistant') {
|
|
782
804
|
msgSeq++
|
|
783
805
|
const cleanReply = (first.text || '').replace(/\s+/g, ' ').trim()
|
|
@@ -818,7 +840,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
818
840
|
allTools.push(...extracted.tools)
|
|
819
841
|
allChanges.push(...extracted.changes)
|
|
820
842
|
|
|
821
|
-
for (const memName of extracted.memories) {
|
|
843
|
+
for (const memName of observedOnly ? [] : extracted.memories) {
|
|
822
844
|
if (!allMemories.includes(memName)) {
|
|
823
845
|
allMemories.push(memName)
|
|
824
846
|
const memTok = 1100
|
|
@@ -855,14 +877,14 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
855
877
|
|
|
856
878
|
const rawMontage = []
|
|
857
879
|
for (const item of toolItems) {
|
|
858
|
-
const dynSchema = resolveDynamicSchema(item, index, schemaIdSet)
|
|
880
|
+
const dynSchema = !observedOnly && resolveDynamicSchema(item, index, schemaIdSet)
|
|
859
881
|
if (dynSchema) {
|
|
860
882
|
schemaIdSet.add(dynSchema.id)
|
|
861
883
|
schemaTokens += dynSchema.tokEst
|
|
862
884
|
stepEstimatedDelta += dynSchema.tokEst
|
|
863
885
|
schemaRecords.push(registerRecord(dynSchema))
|
|
864
886
|
}
|
|
865
|
-
for (const skill of extractSkillNames(item, knownSkillNames)) {
|
|
887
|
+
for (const skill of observedOnly ? [] : extractSkillNames(item, knownSkillNames)) {
|
|
866
888
|
if (!allSkills.includes(skill)) {
|
|
867
889
|
allSkills.push(skill)
|
|
868
890
|
const skTok = 1800
|
|
@@ -997,13 +1019,23 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
997
1019
|
|
|
998
1020
|
const disp = computeDisplayBuckets()
|
|
999
1021
|
prevDisp = disp
|
|
1000
|
-
const
|
|
1001
|
-
const
|
|
1002
|
-
const
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1022
|
+
const bucketTotal = disp.sys + disp.schema + disp.user + disp.mem + disp.msg + disp.tool + disp.skill
|
|
1023
|
+
const previousUsage = observedOnly ? observedUsage : prevTotal
|
|
1024
|
+
const request = observedOnly && group.items.findLast(item => item.contextTokens != null || item.contextTokenEstimates || item.contextWindow != null)
|
|
1025
|
+
const sample = request?.contextTokens
|
|
1026
|
+
if (observedOnly) {
|
|
1027
|
+
const limit = group.items.findLast(item => item.contextWindow != null)?.contextWindow
|
|
1028
|
+
if (limit != null) windowSpec = resolveWindowCapacity(sessionTool, sessionModel, limit)
|
|
1029
|
+
observedUsage = sample ?? null
|
|
1030
|
+
}
|
|
1031
|
+
const totalTokens = observedOnly ? observedUsage : bucketTotal
|
|
1032
|
+
const deltaTokens = totalTokens == null || previousUsage == null ? null : totalTokens - previousUsage
|
|
1033
|
+
const capacity = observedOnly ? windowSpec.tokens : Math.max(windowSpec.tokens, Math.ceil(totalTokens * 1.25))
|
|
1034
|
+
const pct = capacity && totalTokens != null ? Number(((totalTokens / capacity) * 100).toFixed(1)) : null
|
|
1035
|
+
const capPct = value => (!capacity || value <= 0 ? 0 : Number((Math.max(0.4, (value / capacity) * 100)).toFixed(2)))
|
|
1036
|
+
const kindPct = value => Math.round((value / Math.max(1, bucketTotal)) * 100)
|
|
1037
|
+
const buckets = reportedBuckets(disp, request?.contextTokenEstimates)
|
|
1038
|
+
const categories = assembleCategoryList(index, prevCounts, prevToks, buckets)
|
|
1007
1039
|
|
|
1008
1040
|
return {
|
|
1009
1041
|
index,
|
|
@@ -1029,8 +1061,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1029
1061
|
windowTokens: windowSpec.tokens,
|
|
1030
1062
|
windowLabel: windowSpec.label,
|
|
1031
1063
|
totalTokens,
|
|
1064
|
+
...(observedOnly && totalTokens != null && { estimated: false }),
|
|
1032
1065
|
deltaTokens,
|
|
1033
|
-
segments: {
|
|
1066
|
+
segments: observedOnly ? { used: Math.min(pct ?? 0, 100) } : {
|
|
1034
1067
|
sys: capPct(disp.sys),
|
|
1035
1068
|
schema: capPct(disp.schema),
|
|
1036
1069
|
user: capPct(disp.user),
|
|
@@ -1039,7 +1072,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1039
1072
|
skill: capPct(disp.skill),
|
|
1040
1073
|
mem: capPct(disp.mem),
|
|
1041
1074
|
},
|
|
1042
|
-
pctByKind: {
|
|
1075
|
+
pctByKind: observedOnly ? {} : {
|
|
1043
1076
|
sys: kindPct(disp.sys),
|
|
1044
1077
|
schema: kindPct(disp.schema),
|
|
1045
1078
|
user: kindPct(disp.user),
|
|
@@ -1048,15 +1081,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1048
1081
|
skill: kindPct(disp.skill),
|
|
1049
1082
|
mem: kindPct(disp.mem),
|
|
1050
1083
|
},
|
|
1051
|
-
tokensByKind:
|
|
1052
|
-
sys: disp.sys,
|
|
1053
|
-
schema: disp.schema,
|
|
1054
|
-
user: disp.user,
|
|
1055
|
-
msg: disp.msg,
|
|
1056
|
-
tool: disp.tool,
|
|
1057
|
-
skill: disp.skill,
|
|
1058
|
-
mem: disp.mem,
|
|
1059
|
-
},
|
|
1084
|
+
tokensByKind: buckets,
|
|
1060
1085
|
chips: {
|
|
1061
1086
|
tools: uniqueRecent(allTools, 6),
|
|
1062
1087
|
skills: uniqueRecent(allSkills, 4),
|