opencode-acp 1.12.7-dev.1 → 1.12.7

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 CHANGED
@@ -422,13 +422,13 @@ For the complete list with root cause analysis, see the [bug tracker](https://gi
422
422
 
423
423
  ## Changelog
424
424
 
425
- ### v1.12.7-dev.1 — Smart Recommendation Filter + Dangerous Parameter + Deploy Version Guard (PR #142, dev)
425
+ ### v1.12.7 — Smart Recommendation Filter + Dangerous Parameter + Ref-Leak Fix + Phantom Turn Fix (PRs #142, #147, #150)
426
426
 
427
- **Problem**: The recommendation filter had three issues. (1) It used a hardcoded 5× growth threshold for single-message ranges, which was too large (25% of context) and could leak context. (2) The filter showed tiny ranges (71 tokens) alongside meaningful ones. (3) The last segment was always shown with a position-based "recent" annotation, but compressing it requires explicit opt-ina contradiction between recommending and blocking. Additionally, `dev-deploy.sh` deploys were silently overwritten by npm on opencode restart when the npm version was newer than the local version.
427
+ **Problem**: Four issues. (1) The recommendation filter used a hardcoded 5× growth threshold for single-message ranges (25% of context), leaked context, showed tiny ranges, and contradicted itself by recommending the last segment while blocking it. (2) Nudge text was injected even when the filter suppressed all ranges wasting context with an empty recommendation list. (3) Compression block metadata leaked message refs (`m01309–m02150`) via `acp_context_recap` tool input, `acp_status` output, and `recap` tool outputthe model copied these into compress calls on already-compressed ranges, creating phantom blocks (#93, #135). (4) `sendIgnoredMessage` during the transform hook persisted an ignored user message that resolved async after the model's response the loop's `lastUser` detection picked it up → phantom LLM call with no new input → confusion → hallucination → feedback loop ("待命" spam).
428
428
 
429
- **Fix**: (1) Rewrote `filterRecommendedRanges` with a single coherent design: last segment excluded if < 2× growth threshold; included with `dangerous: true` flag if ≥ 2×. Gate: "effective compressible" = non-last-segment tokens + max(0, last-segment floor); suppress all if < growth threshold. (2) Protected ranges no longer affect filtering logic. (3) Replaced state-tracking soft-block with stateless `dangerous?: boolean` parameter on the compress tool schema model must explicitly opt-in to compress the tail. Net −70 lines. (4) Added debug filter decision logging via `sendIgnoredMessage` (model-invisible, user-visible when `debug: true`). (5) `dev-deploy.sh` now queries `npm view` and auto-bumps the deployed version above npm's latest to prevent overwrite on restart.
429
+ **Fix**: (1) Rewrote `filterRecommendedRanges`: last segment excluded if < 2× growth threshold; included with `dangerous: true` flag if ≥ 2×. Stateless `dangerous?: boolean` parameter on compress tool schema replaces state-tracking soft-block. Net −70 lines. (2) Suppress nudge text injection when filter has no recommendations. (3) Stopped leaking message refs: `acp_context_recap` tool input now shows `messages: <count>` instead of `range: "(mN–mN)"`; `acp_status` and `recap` tool output show `N msgs` instead of ref ranges. (4) Debug nudge notification uses `client.tui.showToast()` (transient, non-persisting) + `logger.debug()` (file log) instead of `sendIgnoredMessage` — breaks the phantom-turn feedback loop entirely. `dev-deploy.sh` auto-bumps version above npm latest to prevent overwrite on restart.
430
430
 
431
- Files: `lib/messages/inject/utils.ts`, `lib/messages/inject/inject.ts`, `lib/compress/pipeline.ts`, `lib/compress/range.ts`, `lib/compress/message.ts`, `scripts/dev-deploy.sh`. Tests: `tests/smart-nudge-gating.test.ts` (rewritten, 17 tests), `tests/soft-block.test.ts` (5 tests), `tests/inject.test.ts` (updated). 711 tests pass.
431
+ Files: `lib/messages/inject/utils.ts`, `lib/messages/inject/inject.ts`, `lib/compress/pipeline.ts`, `lib/compress/range.ts`, `lib/compress/message.ts`, `lib/messages/prune.ts`, `lib/messages/utils.ts`, `lib/compress/recap.ts`, `lib/compress/status.ts`, `lib/ui/notification.ts`, `lib/prompts/system.ts`, `lib/hooks.ts`, `scripts/dev-deploy.sh`. Tests: 725 pass.
432
432
 
433
433
  ### v1.12.6 — Stale contextLimitAnchors Fix (PR #143)
434
434
 
package/README.zh-CN.md CHANGED
@@ -395,13 +395,13 @@ ACP 在首次启动时自动将配置从 `dcp.jsonc` 迁移到 `acp.jsonc`,将
395
395
 
396
396
  ## 更新日志
397
397
 
398
- ### v1.12.7-dev.1 — 智能推荐过滤 + Dangerous 参数 + 部署版本守卫(PR #142, dev
398
+ ### v1.12.7 — 智能推荐过滤 + Dangerous 参数 + Ref 泄漏修复 + Phantom Turn 修复(PR #142, #147, #150
399
399
 
400
- **问题**:推荐过滤器有三个问题。(1)使用硬编码的 5× 增长阈值(上下文的 25%),太大且容易泄露上下文。(2)过滤器会显示极小的 range(71 tokens)。(3)最后一段总是显示位置标注 "recent",但压缩它需要显式确认——推荐和阻止矛盾。此外,`dev-deploy.sh` 的部署在 opencode 重启时被 npm 静默覆盖(当 npm 版本比本地新时)。
400
+ **问题**:四个问题。(1)推荐过滤器使用硬编码的 5× 增长阈值(上下文的 25%),太大且容易泄露上下文;推荐最后一段的同时又阻止它,自相矛盾。(2)过滤器抑制所有 range 后仍然注入 nudge 文本——用空推荐列表浪费上下文。(3)压缩块元数据通过 `acp_context_recap` 工具输入、`acp_status` 输出和 `recap` 工具输出泄漏消息 ref(`m01309–m02150`)——模型复制这些 ref 到已压缩范围的 compress 调用中,产生幽灵块(#93, #135)。(4)`sendIgnoredMessage` 在 transform hook 中持久化 ignored 用户消息,异步在模型回复后完成——loop 的 `lastUser` 检测拾取它 → 无新输入的 phantom LLM 调用 → 困惑 → 幻觉 → 反馈循环("待命" 刷屏)。
401
401
 
402
- **修复**:(1)重写 `filterRecommendedRanges`:最后一段 < 2× 增长阈值 → 剔除;≥ 2× → 保留并标记 `dangerous: true`。门槛:"有效可压缩" = 非最后段 + max(0, 最后段 2× 阈值);< 增长阈值则全部抑制。(2)受保护内容不再影响过滤逻辑。(3)用无状态的 `dangerous?: boolean` 参数替换状态追踪 soft-block——模型必须显式 opt-in 才能压缩尾部。净减 70 行。(4)通过 `sendIgnoredMessage` 注入过滤决策调试信息(模型不可见,`debug: true` 时用户可见)。(5)`dev-deploy.sh` 查询 `npm view` 并自动将部署版本 bump npm 最新版之上,防止重启覆盖。
402
+ **修复**:(1)重写 `filterRecommendedRanges`:最后一段 < 2× 增长阈值 → 剔除;≥ 2× → 保留并标记 `dangerous: true`。无状态 `dangerous?: boolean` 参数替代状态追踪 soft-block。净减 70 行。(2)过滤器无推荐时抑制 nudge 文本注入。(3)停止泄漏消息 ref:`acp_context_recap` 工具输入改为 `messages: <数量>`;`acp_status` `recap` 工具输出改为 `N msgs`。(4)Debug nudge 通知改用 `client.tui.showToast()`(瞬态,不持久化)+ `logger.debug()`(文件日志),彻底打破 phantom-turn 反馈循环。`dev-deploy.sh` 自动 bump 版本到 npm 最新之上防止重启覆盖。
403
403
 
404
- 文件:`lib/messages/inject/utils.ts`、`lib/messages/inject/inject.ts`、`lib/compress/pipeline.ts`、`lib/compress/range.ts`、`lib/compress/message.ts`、`scripts/dev-deploy.sh`。测试:`tests/smart-nudge-gating.test.ts`(重写,17 测试)、`tests/soft-block.test.ts`(5 测试)、`tests/inject.test.ts`(更新)。711 测试通过。
404
+ 文件:`lib/messages/inject/utils.ts`、`lib/messages/inject/inject.ts`、`lib/compress/pipeline.ts`、`lib/compress/range.ts`、`lib/compress/message.ts`、`lib/messages/prune.ts`、`lib/messages/utils.ts`、`lib/compress/recap.ts`、`lib/compress/status.ts`、`lib/ui/notification.ts`、`lib/prompts/system.ts`、`lib/hooks.ts`、`scripts/dev-deploy.sh`。测试:725 通过。
405
405
 
406
406
  ### v1.12.6 — Stale contextLimitAnchors 修复(PR #143)
407
407
 
package/dist/index.js CHANGED
@@ -4962,14 +4962,9 @@ function formatEntryRanges(entries, state) {
4962
4962
  for (const entry of entries) {
4963
4963
  const block = state.prune.messages.blocksById.get(entry.blockId);
4964
4964
  if (!block) continue;
4965
- const startRef = block.startId;
4966
- const endRef = block.endId;
4967
- if (!startRef || !endRef) continue;
4968
- if (startRef === endRef) {
4969
- parts.push(`b${entry.blockId}: ${startRef}`);
4970
- } else {
4971
- parts.push(`b${entry.blockId}: ${startRef}\u2013${endRef}`);
4972
- }
4965
+ const count = block.effectiveMessageIds?.length || 0;
4966
+ if (count === 0) continue;
4967
+ parts.push(`b${entry.blockId}: ${count} msg${count !== 1 ? "s" : ""}`);
4973
4968
  }
4974
4969
  return parts.length > 0 ? parts.join(", ") : null;
4975
4970
  }
@@ -5842,7 +5837,7 @@ var createSyntheticMessage = (baseMessage, content, stableSeed, role = "user") =
5842
5837
  return { info, parts };
5843
5838
  };
5844
5839
  var createSyntheticUserMessage = (baseMessage, content, stableSeed) => createSyntheticMessage(baseMessage, content, stableSeed, "user");
5845
- var createSyntheticToolRecap = (baseMessage, summary, blockId, range, stableSeed) => {
5840
+ var createSyntheticToolRecap = (baseMessage, summary, blockId, messageCount, stableSeed) => {
5846
5841
  const baseInfo = baseMessage.info;
5847
5842
  const now = Date.now();
5848
5843
  const messageId = generateStableId("msg_acp_recap", stableSeed);
@@ -5859,7 +5854,7 @@ var createSyntheticToolRecap = (baseMessage, summary, blockId, range, stableSeed
5859
5854
  status: "completed",
5860
5855
  input: {
5861
5856
  blockId,
5862
- ...range ? { range } : {}
5857
+ ...messageCount !== void 0 ? { messages: messageCount } : {}
5863
5858
  },
5864
5859
  output: summary,
5865
5860
  title: `ACP Context Recap (block ${blockId})`,
@@ -6010,10 +6005,9 @@ var dropEmptyMessages = (messages) => {
6010
6005
  };
6011
6006
 
6012
6007
  // lib/messages/prune.ts
6013
- var computeBlockRange = (startId, endId) => {
6014
- if (!startId || !endId) return void 0;
6015
- if (startId === endId) return `(${startId})`;
6016
- return `(${startId}\u2013${endId})`;
6008
+ var computeBlockCoverage = (effectiveMessageIds) => {
6009
+ if (!effectiveMessageIds || effectiveMessageIds.length === 0) return void 0;
6010
+ return effectiveMessageIds.length;
6017
6011
  };
6018
6012
  var prune = (state, logger, config, messages) => {
6019
6013
  filterCompressedRanges(state, logger, config, messages);
@@ -6068,14 +6062,14 @@ var filterCompressedRanges = (state, logger, config, messages) => {
6068
6062
  } else {
6069
6063
  const cleaned = stripStaleMessageRefs(rawSummaryContent);
6070
6064
  const summaryContent = config.compress.mode === "message" ? replaceBlockIdsWithBlocked(cleaned) : cleaned;
6071
- const blockRange = computeBlockRange(summary.startId, summary.endId);
6065
+ const blockCoverage = computeBlockCoverage(summary.effectiveMessageIds);
6072
6066
  const summarySeed = `${summary.blockId}:${summary.anchorMessageId}`;
6073
6067
  result.push(
6074
6068
  createSyntheticToolRecap(
6075
6069
  msg,
6076
6070
  summaryContent,
6077
6071
  summary.blockId,
6078
- blockRange,
6072
+ blockCoverage,
6079
6073
  summarySeed
6080
6074
  )
6081
6075
  );
@@ -7338,7 +7332,6 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
7338
7332
  });
7339
7333
  const growthSinceBaseline = currentTokens !== void 0 && growthReference !== void 0 ? currentTokens - growthReference : void 0;
7340
7334
  const nudgeAllowed = emergencyOverride || decision.shouldNudge && growthSinceBaseline !== void 0 && growthSinceBaseline >= growthFloor;
7341
- state.nudges.shouldInjectThisTurn = nudgeAllowed;
7342
7335
  const effectiveTipsVariant = emergencyOverride ? "maxLimit" : decision.tipsVariant;
7343
7336
  if (nudgeAllowed) {
7344
7337
  applyAnchoredNudges(state, config, messages, prompts, compressionPriorities, currentTokens, modelContextLimit, suffixMessage);
@@ -7353,8 +7346,42 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
7353
7346
  config.compress.protectedTools,
7354
7347
  config.protectedFilePatterns
7355
7348
  );
7349
+ const contextRanges = buildCompressibleRanges(
7350
+ messages,
7351
+ state,
7352
+ config.compress.protectedTools,
7353
+ config.protectedFilePatterns
7354
+ );
7355
+ const recommendedRanges = filterRecommendedRanges(
7356
+ contextRanges.compressible,
7357
+ contextRanges.protected,
7358
+ { modelContextLimit, growthRatio: 0.05, logger }
7359
+ );
7360
+ const hasRecommendations = recommendedRanges.length > 0;
7361
+ if (config.debug && contextRanges.compressible.length > 0 && modelContextLimit) {
7362
+ const growthThreshold = modelContextLimit * 0.05;
7363
+ const lastSegmentFloor = growthThreshold * 2;
7364
+ const compressible = contextRanges.compressible;
7365
+ const lastRange = compressible[compressible.length - 1];
7366
+ const lastIncluded = lastRange.tokens >= lastSegmentFloor;
7367
+ const nonLastTokens = compressible.slice(0, -1).reduce((s, r) => s + r.tokens, 0);
7368
+ const effective = nonLastTokens + Math.max(0, lastRange.tokens - lastSegmentFloor);
7369
+ const suppressed = effective < growthThreshold;
7370
+ const fmt = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}K` : String(n);
7371
+ const lines = [
7372
+ `[ACP Debug] Recommendation filter decision:`,
7373
+ ` Input: ${compressible.length} range(s), ${fmt(compressible.reduce((s, r) => s + r.tokens, 0))} tokens`,
7374
+ ` Thresholds: growth=${fmt(growthThreshold)}, lastSegmentFloor=${fmt(lastSegmentFloor)}`,
7375
+ ` Last segment: ${lastRange.startRef}\u2013${lastRange.endRef} ${fmt(lastRange.tokens)} tokens \u2192 ${lastIncluded ? "included (dangerous)" : "excluded (< floor)"}`,
7376
+ ` Effective compressible: ${fmt(effective)} \u2192 ${suppressed ? "SUPPRESSED (< growth threshold)" : `${recommendedRanges.length} range(s) recommended`}`
7377
+ ];
7378
+ logger.debug(lines.join("\n"));
7379
+ }
7380
+ const filterSuppressed = contextRanges.compressible.length > 0 && !hasRecommendations;
7381
+ const shouldInject = nudgeAllowed && (!filterSuppressed || emergencyOverride);
7382
+ state.nudges.shouldInjectThisTurn = shouldInject;
7356
7383
  let tipsText = null;
7357
- if (nudgeAllowed) {
7384
+ if (shouldInject) {
7358
7385
  injectContextUsage(suffixMessage, config, currentTokens, modelContextLimit);
7359
7386
  if (suffixMessage && composition.total > 0) {
7360
7387
  const fmt = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}K` : String(n);
@@ -7373,36 +7400,6 @@ Breakdown: ${fmt(composition.toolTokens)} tool (${pct2(composition.toolTokens)}%
7373
7400
  breakdown += `
7374
7401
  \u26A0\uFE0F ${fmt(composition.protectedTokens)} tokens are protected (environment-managed tools) \u2014 not compressible. Effective compressible: ~${fmt(compressibleTokens)}.`;
7375
7402
  }
7376
- const contextRanges = buildCompressibleRanges(
7377
- messages,
7378
- state,
7379
- config.compress.protectedTools,
7380
- config.protectedFilePatterns
7381
- );
7382
- const recommendedRanges = filterRecommendedRanges(
7383
- contextRanges.compressible,
7384
- contextRanges.protected,
7385
- { modelContextLimit, growthRatio: 0.05, logger }
7386
- );
7387
- if (debugNotify && contextRanges.compressible.length > 0 && modelContextLimit) {
7388
- const growthThreshold = modelContextLimit * 0.05;
7389
- const lastSegmentFloor = growthThreshold * 2;
7390
- const compressible = contextRanges.compressible;
7391
- const lastRange = compressible[compressible.length - 1];
7392
- const lastIncluded = lastRange.tokens >= lastSegmentFloor;
7393
- const nonLastTokens = compressible.slice(0, -1).reduce((s, r) => s + r.tokens, 0);
7394
- const effective = nonLastTokens + Math.max(0, lastRange.tokens - lastSegmentFloor);
7395
- const suppressed = effective < growthThreshold;
7396
- const fmt2 = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}K` : String(n);
7397
- const lines = [
7398
- `[ACP Debug] Recommendation filter decision:`,
7399
- ` Input: ${compressible.length} range(s), ${fmt2(compressible.reduce((s, r) => s + r.tokens, 0))} tokens`,
7400
- ` Thresholds: growth=${fmt2(growthThreshold)}, lastSegmentFloor=${fmt2(lastSegmentFloor)}`,
7401
- ` Last segment: ${lastRange.startRef}\u2013${lastRange.endRef} ${fmt2(lastRange.tokens)} tokens \u2192 ${lastIncluded ? "included (dangerous)" : "excluded (< floor)"}`,
7402
- ` Effective compressible: ${fmt2(effective)} \u2192 ${suppressed ? "SUPPRESSED (< growth threshold)" : `${recommendedRanges.length} range(s) recommended`}`
7403
- ];
7404
- debugNotify(lines.join("\n"));
7405
- }
7406
7403
  if (recommendedRanges.length > 0) {
7407
7404
  breakdown += `
7408
7405
 
@@ -8043,11 +8040,8 @@ function pct(n, total) {
8043
8040
  return Math.max(1, Math.round(n / total * 100));
8044
8041
  }
8045
8042
  function formatIdRange(block) {
8046
- const start = (block.startId || "").trim();
8047
- const end = (block.endId || "").trim();
8048
- if (!start || !end) return "\u2014";
8049
- if (start === end) return start;
8050
- return `${start}\u2013${end}`;
8043
+ const count = block.effectiveMessageIds?.length || 0;
8044
+ return count > 0 ? `${count} msg${count !== 1 ? "s" : ""}` : "\u2014";
8051
8045
  }
8052
8046
  function collectVisibleMessages(rawMessages, ctx) {
8053
8047
  const pruneMap = ctx.state.prune.messages.byMessageId;
@@ -8338,12 +8332,9 @@ function createAcpStatusTool(ctx) {
8338
8332
 
8339
8333
  // lib/compress/recap.ts
8340
8334
  import { tool as tool6 } from "@opencode-ai/plugin";
8341
- function formatRange(startId, endId) {
8342
- const start = (startId || "").trim();
8343
- const end = (endId || "").trim();
8344
- if (!start || !end) return "\u2014";
8345
- if (start === end) return start;
8346
- return `${start}\u2013${end}`;
8335
+ function formatCoverage(block) {
8336
+ const count = block.effectiveMessageIds?.length || 0;
8337
+ return count > 0 ? `${count} message${count !== 1 ? "s" : ""}` : "\u2014";
8347
8338
  }
8348
8339
  var RECAP_TOOL_DESCRIPTION = `Read-only retrieval of compression block summaries.
8349
8340
 
@@ -8371,7 +8362,7 @@ function createAcpContextRecapTool(ctx) {
8371
8362
  if (!block.active) {
8372
8363
  return `Block b${args.blockId} is inactive (deactivated by GC or nested compression).`;
8373
8364
  }
8374
- const range = formatRange(block.startId, block.endId);
8365
+ const range = formatCoverage(block);
8375
8366
  return `[Compressed conversation section]
8376
8367
  ${block.summary}
8377
8368
 
@@ -8382,7 +8373,7 @@ ${block.summary}
8382
8373
  for (const id of activeIds) {
8383
8374
  const block = msgState.blocksById.get(id);
8384
8375
  if (!block || !block.active) continue;
8385
- const range = formatRange(block.startId, block.endId);
8376
+ const range = formatCoverage(block);
8386
8377
  const summaryPreview = block.summary.slice(0, 200);
8387
8378
  lines.push(`
8388
8379
  b${id} | ${range} | "${block.topic || "(none)"}"`);
@@ -8726,7 +8717,7 @@ Periodically, as context grows, the system appends a short status line in a synt
8726
8717
 
8727
8718
  This line is INFORMATION, not an instruction. Seeing it does not mean you should compress. Compress only when one of the WHEN TO COMPRESS conditions actually holds. Between these lines, context is not under additional pressure \u2014 you do not need to seek things to compress.
8728
8719
 
8729
- If you are unsure which \`mNNNNN\` refs are still compressible, or which blocks have already consumed which ranges, call \`acp_status\` first. It returns the visible context breakdown (tool/code/text/summary tokens with largest items) and the compressed block list (block IDs, sizes, message-ID ranges each covers).
8720
+ If you are unsure which \`mNNNNN\` refs are still compressible, or which blocks have already consumed which ranges, call \`acp_status\` first. It returns the visible context breakdown (tool/code/text/summary tokens with largest items) and the compressed block list (block IDs, sizes, message counts each covers).
8730
8721
 
8731
8722
  CONTEXT BREAKDOWN
8732
8723
 
@@ -10593,15 +10584,17 @@ function createChatMessageTransformHandler(client, state, logger, config, prompt
10593
10584
  output.messages,
10594
10585
  prompts.getRuntimePrompts(),
10595
10586
  compressionPriorities,
10596
- config.debug && state.sessionId ? (text) => {
10597
- sendIgnoredMessage(
10598
- client,
10599
- state.sessionId,
10600
- `[ACP Debug] Nudge injected:
10601
- ${text}`,
10602
- {},
10603
- logger
10604
- ).catch(() => {
10587
+ config.debug ? (text) => {
10588
+ logger.debug(`[ACP Debug] Nudge injected:
10589
+ ${text}`);
10590
+ client.tui.showToast({
10591
+ body: {
10592
+ title: "ACP: Nudge Injected",
10593
+ message: text.slice(0, 500),
10594
+ variant: "info",
10595
+ duration: 5e3
10596
+ }
10597
+ }).catch(() => {
10605
10598
  });
10606
10599
  } : void 0,
10607
10600
  prePruneTokens