@cocorograph/hub-agent 0.8.81 → 0.8.82

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/src/usage.mjs CHANGED
@@ -802,7 +802,7 @@ export function isFreshUnboundBind(boundVal) {
802
802
  * @param {string} cwd
803
803
  * @returns {Promise<{ percent: number | null, uuid: string | null, isReset: boolean }>}
804
804
  */
805
- export async function jsonlContextForCwd(cwd, sessionId = null) {
805
+ export async function jsonlContextForCwd(cwd, sessionId = null, { contextWindow } = {}) {
806
806
  const empty = { percent: null, uuid: null, isReset: false }
807
807
  if (!cwd) return empty
808
808
  const dirName = encodeCwdToDirName(cwd)
@@ -817,12 +817,12 @@ export async function jsonlContextForCwd(cwd, sessionId = null) {
817
817
 
818
818
  // 末尾 assistant.usage を探す。`_jsonlCtxMemo` は fp+mtime+size をキーにしているので
819
819
  // 同 jsonl の連続呼び出しは I/O ゼロでヒットする。
820
+ const windowSize = typeof contextWindow === "number" && contextWindow > 0 ? contextWindow : await contextWindowSize()
820
821
  const memo = _jsonlCtxMemo.get(newest.fp)
821
822
  let percent = null
822
- if (memo && memo.mtimeMs === newest.mtimeMs && memo.size === newest.size) {
823
+ if (memo && memo.mtimeMs === newest.mtimeMs && memo.size === newest.size && memo.windowSize === windowSize) {
823
824
  percent = memo.result ? memo.result.percent : null
824
825
  } else {
825
- const windowSize = await contextWindowSize()
826
826
  const scan = (text) => {
827
827
  const lines = text.split("\n")
828
828
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -857,6 +857,7 @@ export async function jsonlContextForCwd(cwd, sessionId = null) {
857
857
  _jsonlCtxMemo.set(newest.fp, {
858
858
  mtimeMs: newest.mtimeMs,
859
859
  size: newest.size,
860
+ windowSize,
860
861
  result,
861
862
  })
862
863
  }
@@ -2188,6 +2189,10 @@ export function codexContextPercentFromTokenUsage(tokenUsage) {
2188
2189
  /** producer(session.seq) の live context%(App Server 正本)。呼び出し側は cwd の権威 producer
2189
2190
  * (liveSessionForCwd の seq) を渡す。live tokenUsage 未取得 / 算出不能なら null(呼び出し側が
2190
2191
  * rollout へフォールバックする)。 */
2192
+ export function hasCodexLiveTokenUsage(producerSeq) {
2193
+ return _codexLiveTokenUsageByProducer.has(producerSeq)
2194
+ }
2195
+
2191
2196
  export function codexLiveContextForProducer(producerSeq) {
2192
2197
  if (typeof producerSeq !== "number") return null
2193
2198
  const e = _codexLiveTokenUsageByProducer.get(producerSeq)