@infituit/opencode-acp 2.0.0-alpha.8 → 2.0.0-alpha.9
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 +7 -1
- package/dist/index.js +54 -22
- package/dist/index.js.map +1 -1
- package/dist/state/model-limits.d.ts +2 -1
- package/dist/state/model-limits.d.ts.map +1 -1
- package/dist/state/state.d.ts +2 -5
- package/dist/state/state.d.ts.map +1 -1
- package/dist/v2/hooks/messages.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,13 @@ ACP 使用自己的配置文件,按以下顺序加载:
|
|
|
109
109
|
}
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
上下文阈值接受 token 数或模型上下文窗口的百分比。`maxContextLimit`
|
|
112
|
+
上下文阈值接受 token 数或模型上下文窗口的百分比。`maxContextLimit` 是触发压缩提示的软阈值,不是模型的真实上下文窗口,也不是硬性截断上限;达到阈值不代表模型一定立即执行压缩。根据模型的可用上下文调整阈值。
|
|
113
|
+
|
|
114
|
+
`compress.contextLimitFallback` 是模型上下文窗口未知时使用的备用 token 数,默认 `128000`,设为 `0` 可禁用此备用值。从 OpenCode 模型目录(catalog)等来源获知的有效模型窗口优先于 fallback;fallback 不会扩大模型的真实容量。
|
|
115
|
+
|
|
116
|
+
- fallback 偏小,可能使压缩提醒(nudge)、GC 等依赖上下文窗口的机制提前触发;偏大则可能高估可用预算,来不及在真实窗口耗尽前提醒或回收。
|
|
117
|
+
- 优先在 OpenCode 的 provider/model 配置中补齐或修正实际的 `limit.context`(参见 [OpenCode 模型配置](https://opencode.ai/v2/docs/models)),不要盲目调大 fallback 来延后提醒。
|
|
118
|
+
- 禁用 fallback 后,若仍无法获知模型窗口,依赖该窗口的机制可能不可用;这不代表模型拥有无限上下文。
|
|
113
119
|
|
|
114
120
|
### 按 Provider / 按模型覆盖
|
|
115
121
|
|
package/dist/index.js
CHANGED
|
@@ -3568,7 +3568,7 @@ function applyPendingCompressionDurations(state) {
|
|
|
3568
3568
|
}
|
|
3569
3569
|
|
|
3570
3570
|
// src/state/model-limits.ts
|
|
3571
|
-
function createModelLimitCatalog() {
|
|
3571
|
+
function createModelLimitCatalog(logger) {
|
|
3572
3572
|
const modelLimits = /* @__PURE__ */ new Map();
|
|
3573
3573
|
return {
|
|
3574
3574
|
record(providerId, modelId, limit) {
|
|
@@ -3580,14 +3580,27 @@ function createModelLimitCatalog() {
|
|
|
3580
3580
|
return modelLimits.get(`${providerId}/${modelId}`);
|
|
3581
3581
|
},
|
|
3582
3582
|
/**
|
|
3583
|
-
* Best-effort
|
|
3583
|
+
* Best-effort load from the V2 model catalog. Never throws;
|
|
3584
3584
|
* returns the number of model-limit entries recorded.
|
|
3585
3585
|
*/
|
|
3586
3586
|
async hydrateFromClient(client) {
|
|
3587
3587
|
try {
|
|
3588
3588
|
const v2Client = client;
|
|
3589
|
+
if (typeof v2Client?.model?.list !== "function") {
|
|
3590
|
+
logger?.warn("Model limit catalog load failed", {
|
|
3591
|
+
reason: "api_unavailable",
|
|
3592
|
+
catalogSize: modelLimits.size
|
|
3593
|
+
});
|
|
3594
|
+
return 0;
|
|
3595
|
+
}
|
|
3589
3596
|
const response = await v2Client.model.list();
|
|
3590
|
-
if (!Array.isArray(response
|
|
3597
|
+
if (!Array.isArray(response?.data)) {
|
|
3598
|
+
logger?.warn("Model limit catalog load failed", {
|
|
3599
|
+
reason: "invalid_response",
|
|
3600
|
+
catalogSize: modelLimits.size
|
|
3601
|
+
});
|
|
3602
|
+
return 0;
|
|
3603
|
+
}
|
|
3591
3604
|
let recorded = 0;
|
|
3592
3605
|
for (const value of response.data) {
|
|
3593
3606
|
if (!value || typeof value !== "object") continue;
|
|
@@ -3598,8 +3611,19 @@ function createModelLimitCatalog() {
|
|
|
3598
3611
|
modelLimits.set(`${model.providerID}/${model.id}`, model.limit.context);
|
|
3599
3612
|
recorded++;
|
|
3600
3613
|
}
|
|
3614
|
+
logger?.info("Model limit catalog loaded", {
|
|
3615
|
+
reason: response.data.length === 0 ? "empty_catalog" : recorded === 0 ? "no_valid_limits" : "loaded",
|
|
3616
|
+
entries: response.data.length,
|
|
3617
|
+
recorded,
|
|
3618
|
+
skipped: response.data.length - recorded,
|
|
3619
|
+
catalogSize: modelLimits.size
|
|
3620
|
+
});
|
|
3601
3621
|
return recorded;
|
|
3602
3622
|
} catch {
|
|
3623
|
+
logger?.warn("Model limit catalog load failed", {
|
|
3624
|
+
reason: "request_failed",
|
|
3625
|
+
catalogSize: modelLimits.size
|
|
3626
|
+
});
|
|
3603
3627
|
return 0;
|
|
3604
3628
|
}
|
|
3605
3629
|
}
|
|
@@ -5185,10 +5209,12 @@ async function updatePerTurnState(state, logger, messages) {
|
|
|
5185
5209
|
state.currentTurn = countTurns(state, messages);
|
|
5186
5210
|
}
|
|
5187
5211
|
var REGISTRY_SOFT_CAP = 32;
|
|
5212
|
+
var MODEL_LIMIT_RETRY_INTERVAL_MS = 3e4;
|
|
5188
5213
|
var SessionStateRegistry = class {
|
|
5189
5214
|
constructor(logger, projectDir) {
|
|
5190
5215
|
this.logger = logger;
|
|
5191
5216
|
this.projectDir = projectDir;
|
|
5217
|
+
this.catalog = createModelLimitCatalog(logger);
|
|
5192
5218
|
}
|
|
5193
5219
|
logger;
|
|
5194
5220
|
projectDir;
|
|
@@ -5202,38 +5228,41 @@ var SessionStateRegistry = class {
|
|
|
5202
5228
|
// model named on the request's user message instead of waiting one turn
|
|
5203
5229
|
// for the system hook. Shared implementation — the test registry stub
|
|
5204
5230
|
// composes the same factory.
|
|
5205
|
-
catalog
|
|
5231
|
+
catalog;
|
|
5206
5232
|
recordModelLimit(providerId, modelId, limit) {
|
|
5207
5233
|
this.catalog.record(providerId, modelId, limit);
|
|
5208
5234
|
}
|
|
5209
5235
|
resolveModelLimit(providerId, modelId) {
|
|
5210
5236
|
return this.catalog.resolve(providerId, modelId);
|
|
5211
5237
|
}
|
|
5212
|
-
/**
|
|
5213
|
-
* Best-effort one-time seed from the host's provider catalog
|
|
5214
|
-
* V2 model catalog. Never throws; returns the number of model-limit entries recorded.
|
|
5215
|
-
* returns the number of model-limit entries recorded.
|
|
5216
|
-
*/
|
|
5238
|
+
/** Best-effort seed from the V2 model catalog; returns the number of recorded entries. */
|
|
5217
5239
|
hydrateModelLimitsFromClient(client) {
|
|
5218
5240
|
return this.catalog.hydrateFromClient(client);
|
|
5219
5241
|
}
|
|
5220
|
-
//
|
|
5221
|
-
//
|
|
5222
|
-
//
|
|
5223
|
-
// the process's lifetime. During a request the server is guaranteed up
|
|
5224
|
-
// (we are inside its pipeline), so on a catalog miss we retry hydration
|
|
5225
|
-
// once per process before giving up (the fallback limit then applies).
|
|
5226
|
-
// The in-flight promise (not a boolean) lets concurrent callers await the
|
|
5227
|
-
// same hydration instead of skipping it.
|
|
5242
|
+
// Initialization can precede provider readiness. Retry request-time misses,
|
|
5243
|
+
// sharing in-flight work and cooling down completed attempts so an unknown
|
|
5244
|
+
// model cannot cause a catalog request on every turn. Cache hits never wait.
|
|
5228
5245
|
lazyHydration;
|
|
5246
|
+
nextModelLimitRetryAt = 0;
|
|
5229
5247
|
async hydrateAndResolve(client, providerId, modelId) {
|
|
5230
5248
|
const existing = this.catalog.resolve(providerId, modelId);
|
|
5231
5249
|
if (existing !== void 0) {
|
|
5232
5250
|
return existing;
|
|
5233
5251
|
}
|
|
5234
|
-
this.lazyHydration
|
|
5252
|
+
if (!this.lazyHydration && Date.now() >= this.nextModelLimitRetryAt) {
|
|
5253
|
+
this.lazyHydration = this.catalog.hydrateFromClient(client).finally(() => {
|
|
5254
|
+
this.nextModelLimitRetryAt = Date.now() + MODEL_LIMIT_RETRY_INTERVAL_MS;
|
|
5255
|
+
this.lazyHydration = void 0;
|
|
5256
|
+
});
|
|
5257
|
+
}
|
|
5235
5258
|
await this.lazyHydration;
|
|
5236
|
-
|
|
5259
|
+
const limit = this.catalog.resolve(providerId, modelId);
|
|
5260
|
+
this.logger.debug("Model limit catalog lookup", {
|
|
5261
|
+
model: `${providerId}/${modelId}`,
|
|
5262
|
+
reason: limit === void 0 ? "model_not_found" : "model",
|
|
5263
|
+
retryAfterMs: limit === void 0 ? Math.max(0, this.nextModelLimitRetryAt - Date.now()) : 0
|
|
5264
|
+
});
|
|
5265
|
+
return limit;
|
|
5237
5266
|
}
|
|
5238
5267
|
get(sessionId) {
|
|
5239
5268
|
return this.states.get(sessionId);
|
|
@@ -11517,7 +11546,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
|
11517
11546
|
import { join as join5 } from "path";
|
|
11518
11547
|
import { existsSync as existsSync5 } from "fs";
|
|
11519
11548
|
import { homedir as homedir3 } from "os";
|
|
11520
|
-
var LOG_VERSION = true ? "2.0.0-alpha.
|
|
11549
|
+
var LOG_VERSION = true ? "2.0.0-alpha.9" : "dev";
|
|
11521
11550
|
var LEVEL_RANK = {
|
|
11522
11551
|
debug: 10,
|
|
11523
11552
|
info: 20,
|
|
@@ -13399,11 +13428,14 @@ function createChatMessageTransformHandler(client, registry4, logger, config, pr
|
|
|
13399
13428
|
checkpoint("permissions");
|
|
13400
13429
|
if (state.modelContextLimit === void 0 && !state.noContextLimitWarned && requestModel?.providerID && requestModel?.modelID && registry4.resolveModelLimit(requestModel.providerID, requestModel.modelID) === void 0) {
|
|
13401
13430
|
state.noContextLimitWarned = true;
|
|
13431
|
+
const effectiveLimit2 = resolveEffectiveContextLimit(state, config);
|
|
13402
13432
|
logger.warn(
|
|
13403
|
-
|
|
13433
|
+
effectiveLimit2 ? "Model context window is unavailable in the catalog; using compress.contextLimitFallback. A smaller fallback may trigger compression early; a larger one may overestimate the available budget. Check the provider/model limit in OpenCode and the model catalog load logs. Catalog misses are retried on later requests with a cooldown." : "Model context window is unavailable in the catalog and compress.contextLimitFallback is disabled; checks that require a context window cannot run. Absolute compress.maxContextLimit can still trigger proactive nudges. Check the provider/model limit in OpenCode and the model catalog load logs. Catalog misses are retried on later requests with a cooldown.",
|
|
13404
13434
|
{
|
|
13405
13435
|
session: state.sessionId,
|
|
13406
|
-
model: `${requestModel.providerID}/${requestModel.modelID}
|
|
13436
|
+
model: `${requestModel.providerID}/${requestModel.modelID}`,
|
|
13437
|
+
contextLimit: effectiveLimit2?.limit ?? 0,
|
|
13438
|
+
contextLimitSource: effectiveLimit2?.source ?? "unknown"
|
|
13407
13439
|
}
|
|
13408
13440
|
);
|
|
13409
13441
|
}
|