@triflux/core 10.28.0 → 10.28.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.
@@ -142,7 +142,7 @@ function contextPercentsFromObject(value) {
142
142
  ];
143
143
 
144
144
  const currentUsage = value.current_usage ?? value.currentUsage ?? {};
145
- const maxTokens =
145
+ const explicitMaxTokens =
146
146
  value.context_window_size ??
147
147
  value.contextWindowSize ??
148
148
  value.max_context_tokens ??
@@ -151,6 +151,18 @@ function contextPercentsFromObject(value) {
151
151
  value.maxTokens ??
152
152
  value.total_tokens ??
153
153
  value.totalTokens;
154
+ // Fall back to a 1M context window when the payload omits one — Opus 4.x
155
+ // [1M] and Codex gpt-5.5 both run on a 1M window, and assuming 200K there
156
+ // false-positives at ~15% real usage. Override via
157
+ // TFX_CONTEXT_DEFAULT_MAX_TOKENS for narrower setups.
158
+ const envFallback = Number(process.env.TFX_CONTEXT_DEFAULT_MAX_TOKENS);
159
+ const fallbackMaxTokens =
160
+ Number.isFinite(envFallback) && envFallback > 0 ? envFallback : 1_000_000;
161
+ const explicitNumeric = Number(explicitMaxTokens);
162
+ const maxTokens =
163
+ Number.isFinite(explicitNumeric) && explicitNumeric > 0
164
+ ? explicitNumeric
165
+ : fallbackMaxTokens;
154
166
  candidates.push(
155
167
  tokenPercent(value.used_tokens ?? value.usedTokens, maxTokens),
156
168
  tokenPercent(
@@ -288,11 +288,16 @@ export function buildContextUsageView(stdin, snapshot = null) {
288
288
  const modelHintLimit = resolveModelLimit(modelId);
289
289
  const monitorLimit = Number(monitor?.limitTokens || 0);
290
290
  const stdinLimit = stdinUsage?.limitTokens;
291
+ // When a model id is known it is the authoritative per-model ceiling: the
292
+ // monitor's cached limitTokens is just a default-derived accumulator (now 1M
293
+ // by default) and must not override a known model's real window in either
294
+ // direction — it would inflate a 200K model (Sonnet 4.5 / Haiku) up to 1M.
295
+ // The model hint already upgrades a stale-low monitor on its own (#88).
291
296
  const limitTokens =
292
297
  stdinLimit != null && stdinLimit > 0
293
298
  ? Math.max(1, stdinLimit)
294
299
  : modelId
295
- ? Math.max(1, monitorLimit, modelHintLimit)
300
+ ? Math.max(1, modelHintLimit)
296
301
  : Math.max(1, monitorLimit || modelHintLimit);
297
302
 
298
303
  const usedTokens = stdinUsage?.usedTokens ?? Number(monitor?.usedTokens || 0);
@@ -324,7 +329,19 @@ export function buildContextUsageView(stdin, snapshot = null) {
324
329
  }
325
330
 
326
331
  export function createContextMonitor(options = {}) {
327
- const limitTokens = Number(options.limitTokens || DEFAULT_CONTEXT_LIMIT);
332
+ // Default to a 1M context window (Opus 4.x [1M] / Codex gpt-5.5 both run on
333
+ // a 1M window) when no explicit limit is supplied, so the cached percent the
334
+ // Stop hook reads is not inflated against a 200K assumption — assuming 200K
335
+ // there false-positives at ~15% real usage and blocks legitimate stops.
336
+ // Narrower setups override via TFX_CONTEXT_DEFAULT_MAX_TOKENS.
337
+ const explicitLimit = Number(options.limitTokens);
338
+ const envLimit = Number(process.env.TFX_CONTEXT_DEFAULT_MAX_TOKENS);
339
+ const limitTokens =
340
+ Number.isFinite(explicitLimit) && explicitLimit > 0
341
+ ? explicitLimit
342
+ : Number.isFinite(envLimit) && envLimit > 0
343
+ ? envLimit
344
+ : MILLION_CONTEXT_LIMIT;
328
345
  const cachePath = options.cachePath || CONTEXT_MONITOR_CACHE_PATH;
329
346
  const logsDir = options.logsDir || CONTEXT_MONITOR_LOG_DIR;
330
347
  const sessionId = options.sessionId || randomUUID().slice(0, 8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triflux/core",
3
- "version": "10.28.0",
3
+ "version": "10.28.1",
4
4
  "description": "triflux core — CLI routing, pipeline, adapters. Zero native dependencies.",
5
5
  "type": "module",
6
6
  "main": "hub/index.mjs",