opencode-acp 1.18.2-pr.447.191 → 1.18.2-pr.449.193

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/dist/index.js CHANGED
@@ -9832,6 +9832,81 @@ function computeRestoredMessages(messagesState, activeMessagesBefore) {
9832
9832
  }
9833
9833
  return { restoredMessageCount, restoredTokens };
9834
9834
  }
9835
+ function collectRequiredDecompressMessageIds(messagesState, targets, options = {}) {
9836
+ const targetBlockIds = /* @__PURE__ */ new Set();
9837
+ for (const target of targets) {
9838
+ for (const block of target.blocks) {
9839
+ targetBlockIds.add(block.blockId);
9840
+ }
9841
+ }
9842
+ if (targetBlockIds.size === 0) {
9843
+ return [];
9844
+ }
9845
+ const consumedClosure = /* @__PURE__ */ new Set();
9846
+ const queue = [];
9847
+ for (const target of targets) {
9848
+ for (const block of target.blocks) {
9849
+ for (const id of block.consumedBlockIds ?? []) {
9850
+ if (!consumedClosure.has(id)) {
9851
+ queue.push(id);
9852
+ }
9853
+ }
9854
+ }
9855
+ }
9856
+ while (queue.length > 0) {
9857
+ const id = queue.shift();
9858
+ if (consumedClosure.has(id)) continue;
9859
+ consumedClosure.add(id);
9860
+ const consumed = messagesState.blocksById.get(id);
9861
+ if (consumed) {
9862
+ for (const nested of consumed.consumedBlockIds ?? []) {
9863
+ if (!consumedClosure.has(nested)) {
9864
+ queue.push(nested);
9865
+ }
9866
+ }
9867
+ }
9868
+ }
9869
+ let shieldedMessageIds = null;
9870
+ if (!options.full) {
9871
+ shieldedMessageIds = /* @__PURE__ */ new Set();
9872
+ for (const id of consumedClosure) {
9873
+ const block = messagesState.blocksById.get(id);
9874
+ if (!block || block.deactivatedByUser || block.deactivatedByUserDeep) continue;
9875
+ for (const messageId of block.effectiveMessageIds ?? []) {
9876
+ shieldedMessageIds.add(messageId);
9877
+ }
9878
+ }
9879
+ }
9880
+ const required = [];
9881
+ for (const [messageId, entry] of messagesState.byMessageId) {
9882
+ if (entry.activeBlockIds.length === 0) continue;
9883
+ let exclusivelyCoveredByTargets = true;
9884
+ for (const blockId of entry.activeBlockIds) {
9885
+ if (!targetBlockIds.has(blockId)) {
9886
+ exclusivelyCoveredByTargets = false;
9887
+ break;
9888
+ }
9889
+ }
9890
+ if (!exclusivelyCoveredByTargets) continue;
9891
+ if (shieldedMessageIds?.has(messageId)) continue;
9892
+ required.push(messageId);
9893
+ }
9894
+ required.sort();
9895
+ return required;
9896
+ }
9897
+ function checkDecompressSourceAvailability(messagesState, targets, options, presentInHistory) {
9898
+ const requiredMessageIds = collectRequiredDecompressMessageIds(messagesState, targets, options);
9899
+ const available = [];
9900
+ const missing = [];
9901
+ for (const messageId of requiredMessageIds) {
9902
+ if (presentInHistory.has(messageId)) {
9903
+ available.push(messageId);
9904
+ } else {
9905
+ missing.push(messageId);
9906
+ }
9907
+ }
9908
+ return { requiredMessageIds, availableMessageIds: available, missingMessageIds: missing };
9909
+ }
9835
9910
  function computeReactivatedBlockIds(messagesState, activeBlockIdsBefore) {
9836
9911
  return Array.from(messagesState.activeBlockIds).filter((blockId) => !activeBlockIdsBefore.has(blockId)).sort((a, b) => a - b);
9837
9912
  }
@@ -10040,14 +10115,31 @@ function buildSchema2() {
10040
10115
  };
10041
10116
  }
10042
10117
  function extractMessageId(m) {
10043
- return m.id ?? m.messageId ?? "";
10118
+ return m?.info?.id ?? "";
10119
+ }
10120
+ function serializeMessagePart(part) {
10121
+ if (!part || typeof part !== "object") return null;
10122
+ if (part.type === "text") {
10123
+ return typeof part.text === "string" && part.text.length > 0 ? part.text : null;
10124
+ }
10125
+ if (part.type === "tool") {
10126
+ const contents = extractToolContent(part);
10127
+ if (contents.length === 0) return null;
10128
+ const toolName = "tool" in part && typeof part.tool === "string" && part.tool.length > 0 ? part.tool : "tool";
10129
+ return `[${toolName}] ${contents.join("\n")}`;
10130
+ }
10131
+ return null;
10044
10132
  }
10045
10133
  function extractMessageText2(m) {
10046
- const msg = m;
10047
- const role = msg.role || msg.type || "unknown";
10048
- const content = typeof msg.content === "string" ? msg.content : typeof msg.text === "string" ? msg.text : JSON.stringify(msg.content || msg.text || "");
10134
+ const role = m?.info?.role ?? "unknown";
10135
+ const parts = Array.isArray(m.parts) ? m.parts : [];
10136
+ const segments = [];
10137
+ for (const part of parts) {
10138
+ const serialized = serializeMessagePart(part);
10139
+ if (serialized !== null) segments.push(serialized);
10140
+ }
10049
10141
  return `[${role}]
10050
- ${content}`;
10142
+ ${segments.join("\n\n")}`;
10051
10143
  }
10052
10144
  function createDecompressTool(factoryCtx) {
10053
10145
  return tool3({
@@ -10099,10 +10191,40 @@ function createDecompressTool(factoryCtx) {
10099
10191
  const blockMessages = rawMessages.filter((m) => msgIdSet.has(extractMessageId(m)));
10100
10192
  const lines2 = blockMessages.map(extractMessageText2);
10101
10193
  const { writeFile: writeFile4 } = await import("fs/promises");
10102
- const fileContent = lines2.length > 0 ? lines2.join("\n\n---\n\n") : targets[0]?.blocks[0]?.summary ?? "(no content available)";
10194
+ let fileContent;
10195
+ let sourceNote;
10196
+ if (lines2.length > 0) {
10197
+ fileContent = lines2.join("\n\n---\n\n");
10198
+ sourceNote = `${blockMessages.length} original message${blockMessages.length === 1 ? "" : "s"}`;
10199
+ } else {
10200
+ fileContent = targets[0]?.blocks[0]?.summary ?? "(no content available)";
10201
+ sourceNote = `no original messages found; wrote block summary (${targets.length} block${targets.length === 1 ? "" : "s"})`;
10202
+ }
10103
10203
  await writeFile4(targetPath, fileContent, "utf-8");
10104
10204
  const displayIds2 = targets.map((t) => `b${t.displayId}`).join(", ");
10105
- return `Block(s) ${displayIds2} content (${blockMessages.length} messages, ${fileContent.length} chars) written to ${targetPath}. Block(s) stay compressed \u2014 context unchanged. Use read tool to access specific parts.`;
10205
+ return `Block(s) ${displayIds2} content (${sourceNote}, ${fileContent.length} chars) written to ${targetPath}. Block(s) stay compressed \u2014 context unchanged. Use read tool to access specific parts.`;
10206
+ }
10207
+ const availability = checkDecompressSourceAvailability(
10208
+ messagesState,
10209
+ targets,
10210
+ { full: args.full === true },
10211
+ new Set(rawMessages.map((m) => m.info.id))
10212
+ );
10213
+ if (availability.missingMessageIds.length > 0) {
10214
+ const displayIds2 = targets.map((t) => `b${t.displayId}`).join(", ");
10215
+ const missingRefs = availability.missingMessageIds.map(
10216
+ (id) => ctx.state.messageIds.byRawId.get(id) ?? id
10217
+ );
10218
+ const shownRefs = missingRefs.slice(0, 10).join(", ");
10219
+ const extraCount = missingRefs.length - Math.min(missingRefs.length, 10);
10220
+ ctx.logger.warn("Decompress aborted: source messages missing from host history", {
10221
+ targetDisplayIds: displayIds2,
10222
+ full: args.full === true,
10223
+ requiredCount: availability.requiredMessageIds.length,
10224
+ missingCount: availability.missingMessageIds.length,
10225
+ missingRefs
10226
+ });
10227
+ return `Error: Cannot decompress ${displayIds2}: ${availability.missingMessageIds.length} of ${availability.requiredMessageIds.length} source message(s) are no longer present in session history (removed by native compaction or external deletion). Missing: ${shownRefs}` + (extraCount > 0 ? ` (+${extraCount} more)` : "") + `. Block(s) stay compressed \u2014 the summary remains available and nothing was changed. This is a missing-source condition, not a transient fetch failure.`;
10106
10228
  }
10107
10229
  const activeMessagesBefore = snapshotActiveMessages(messagesState);
10108
10230
  const activeBlockIdsBefore = new Set(messagesState.activeBlockIds);
@@ -10915,7 +11037,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
10915
11037
  import { join as join4 } from "path";
10916
11038
  import { existsSync as existsSync4 } from "fs";
10917
11039
  import { homedir as homedir3 } from "os";
10918
- var LOG_VERSION = true ? "1.18.2-pr.447.191" : "dev";
11040
+ var LOG_VERSION = true ? "1.18.2-pr.449.193" : "dev";
10919
11041
  var LEVEL_RANK = {
10920
11042
  debug: 10,
10921
11043
  info: 20,
@@ -13633,7 +13755,7 @@ var server = (async (ctx) => {
13633
13755
  }
13634
13756
  const logger = new Logger(config.debug, config.debug ? "debug" : config.logLevel);
13635
13757
  logger.info("ACP plugin initialized", {
13636
- version: true ? "1.18.2-pr.447.191" : "dev",
13758
+ version: true ? "1.18.2-pr.449.193" : "dev",
13637
13759
  workspace: ctx.directory,
13638
13760
  logLevel: logger.level,
13639
13761
  debug: config.debug,