@tarquinen/opencode-dcp 3.1.10 → 3.1.12

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
@@ -146,6 +146,8 @@ Each level overrides the previous, so project settings take priority over global
146
146
  "nudgeForce": "soft",
147
147
  // Tool names whose completed outputs are appended to the compression
148
148
  "protectedTools": [],
149
+ // Preserve text wrapped in <protect>...</protect> when compressed
150
+ "protectTags": false,
149
151
  // Preserve your messages during compression.
150
152
  // Warning: large copy-pasted prompts will never be compressed away
151
153
  "protectUserMessages": false,
package/dist/index.js CHANGED
@@ -910,6 +910,7 @@ var VALID_CONFIG_KEYS = /* @__PURE__ */ new Set([
910
910
  "compress.iterationNudgeThreshold",
911
911
  "compress.nudgeForce",
912
912
  "compress.protectedTools",
913
+ "compress.protectTags",
913
914
  "compress.protectUserMessages",
914
915
  "strategies",
915
916
  "strategies.deduplication",
@@ -1140,6 +1141,13 @@ function validateConfigTypes(config) {
1140
1141
  actual: typeof compress.protectedTools
1141
1142
  });
1142
1143
  }
1144
+ if (compress.protectTags !== void 0 && typeof compress.protectTags !== "boolean") {
1145
+ errors.push({
1146
+ key: "compress.protectTags",
1147
+ expected: "boolean",
1148
+ actual: typeof compress.protectTags
1149
+ });
1150
+ }
1143
1151
  if (compress.protectUserMessages !== void 0 && typeof compress.protectUserMessages !== "boolean") {
1144
1152
  errors.push({
1145
1153
  key: "compress.protectUserMessages",
@@ -1333,6 +1341,7 @@ var defaultConfig = {
1333
1341
  iterationNudgeThreshold: 15,
1334
1342
  nudgeForce: "soft",
1335
1343
  protectedTools: [...COMPRESS_DEFAULT_PROTECTED_TOOLS],
1344
+ protectTags: false,
1336
1345
  protectUserMessages: false
1337
1346
  },
1338
1347
  strategies: {
@@ -1455,6 +1464,7 @@ function mergeCompress(base, override) {
1455
1464
  iterationNudgeThreshold: override.iterationNudgeThreshold ?? base.iterationNudgeThreshold,
1456
1465
  nudgeForce: override.nudgeForce ?? base.nudgeForce,
1457
1466
  protectedTools: [.../* @__PURE__ */ new Set([...base.protectedTools, ...override.protectedTools ?? []])],
1467
+ protectTags: override.protectTags ?? base.protectTags,
1458
1468
  protectUserMessages: override.protectUserMessages ?? base.protectUserMessages
1459
1469
  };
1460
1470
  }
@@ -3991,6 +4001,43 @@ function appendProtectedUserMessages(summary, selection, searchContext, state, e
3991
4001
  ${text}`).join("");
3992
4002
  return summary + heading + body;
3993
4003
  }
4004
+ function appendProtectedPromptInfo(summary, selection, searchContext, state, enabled) {
4005
+ if (!enabled) return summary;
4006
+ const protectedTexts = [];
4007
+ for (const messageId of selection.messageIds) {
4008
+ const existingCompressionEntry = state.prune.messages.byMessageId.get(messageId);
4009
+ if (existingCompressionEntry && existingCompressionEntry.activeBlockIds.length > 0) {
4010
+ continue;
4011
+ }
4012
+ const message = searchContext.rawMessagesById.get(messageId);
4013
+ if (!message) continue;
4014
+ if (message.info.role !== "user") continue;
4015
+ if (isIgnoredUserMessage(message)) continue;
4016
+ const parts = Array.isArray(message.parts) ? message.parts : [];
4017
+ for (const part of parts) {
4018
+ if (part.type !== "text" || typeof part.text !== "string") continue;
4019
+ protectedTexts.push(...extractProtectedPromptInfo(part.text));
4020
+ }
4021
+ }
4022
+ if (protectedTexts.length === 0) {
4023
+ return summary;
4024
+ }
4025
+ const heading = "\n\nThe following protected prompt information was included in this conversation verbatim:";
4026
+ const body = protectedTexts.map((text) => `
4027
+ ${text}`).join("");
4028
+ return summary + heading + body;
4029
+ }
4030
+ function extractProtectedPromptInfo(text) {
4031
+ const protectedTexts = [];
4032
+ const protectTagRegex = /<protect>([\s\S]*?)<\/protect>/gi;
4033
+ for (const match of text.matchAll(protectTagRegex)) {
4034
+ const protectedText = match[1]?.trim();
4035
+ if (protectedText) {
4036
+ protectedTexts.push(protectedText);
4037
+ }
4038
+ }
4039
+ return protectedTexts;
4040
+ }
3994
4041
  async function appendProtectedTools(client, state, allowSubAgents, summary, selection, searchContext, protectedTools, protectedFilePatterns = []) {
3995
4042
  const protectedOutputs = [];
3996
4043
  for (const messageId of selection.messageIds) {
@@ -4106,11 +4153,18 @@ function createCompressMessageTool(ctx) {
4106
4153
  const notifications = [];
4107
4154
  const preparedPlans = [];
4108
4155
  for (const plan of plans) {
4156
+ const summaryWithPromptInfo = appendProtectedPromptInfo(
4157
+ plan.entry.summary,
4158
+ plan.selection,
4159
+ searchContext,
4160
+ ctx.state,
4161
+ ctx.config.compress.protectTags
4162
+ );
4109
4163
  const summaryWithTools = await appendProtectedTools(
4110
4164
  ctx.client,
4111
4165
  ctx.state,
4112
4166
  ctx.config.experimental.allowSubAgents,
4113
- plan.entry.summary,
4167
+ summaryWithPromptInfo,
4114
4168
  plan.selection,
4115
4169
  searchContext,
4116
4170
  ctx.config.compress.protectedTools,
@@ -4445,11 +4499,18 @@ function createCompressRangeTool(ctx) {
4445
4499
  ctx.state,
4446
4500
  ctx.config.compress.protectUserMessages
4447
4501
  );
4502
+ const summaryWithPromptInfo = appendProtectedPromptInfo(
4503
+ summaryWithUsers,
4504
+ plan.selection,
4505
+ searchContext,
4506
+ ctx.state,
4507
+ ctx.config.compress.protectTags
4508
+ );
4448
4509
  const summaryWithTools = await appendProtectedTools(
4449
4510
  ctx.client,
4450
4511
  ctx.state,
4451
4512
  ctx.config.experimental.allowSubAgents,
4452
- summaryWithUsers,
4513
+ summaryWithPromptInfo,
4453
4514
  plan.selection,
4454
4515
  searchContext,
4455
4516
  ctx.config.compress.protectedTools,
@@ -5797,12 +5858,6 @@ function listPriorityRefsBeforeIndex(messages, priorities, anchorIndex, priority
5797
5858
 
5798
5859
  // lib/messages/inject/utils.ts
5799
5860
  var MESSAGE_MODE_NUDGE_PRIORITY = "high";
5800
- function computeInputBudget(limit) {
5801
- if (!limit.context) {
5802
- return void 0;
5803
- }
5804
- return limit.input ?? Math.max(0, limit.context - (limit.output ?? 0));
5805
- }
5806
5861
  function getNudgeFrequency(config) {
5807
5862
  return Math.max(1, Math.floor(config.compress.nudgeFrequency || 1));
5808
5863
  }
@@ -7341,10 +7396,7 @@ var INTERNAL_AGENT_SIGNATURES = [
7341
7396
  function createSystemPromptHandler(state, logger, config, prompts) {
7342
7397
  return async (input, output) => {
7343
7398
  if (input.model?.limit?.context) {
7344
- const inputBudget = computeInputBudget(input.model.limit);
7345
- if (inputBudget !== void 0) {
7346
- state.modelContextLimit = inputBudget;
7347
- }
7399
+ state.modelContextLimit = input.model.limit.context;
7348
7400
  logger.debug("Cached model context limit", { limit: state.modelContextLimit });
7349
7401
  }
7350
7402
  if (state.isSubAgent && !config.experimental.allowSubAgents) {
@@ -7674,10 +7726,22 @@ async function updateRemoveDir(packageDir, name) {
7674
7726
  if (basename(nodeModulesDir) !== "node_modules") return void 0;
7675
7727
  const wrapperDir = dirname3(nodeModulesDir);
7676
7728
  const wrapperPkg = await readPackageJson(join5(wrapperDir, "package.json"));
7677
- const spec = wrapperPkg?.dependencies?.[name];
7729
+ const spec = wrapperSpec(wrapperDir, name) ?? wrapperPkg?.dependencies?.[name];
7678
7730
  if (!spec || !isAutoUpdatableSpec(spec)) return void 0;
7679
7731
  return wrapperDir;
7680
7732
  }
7733
+ function wrapperSpec(wrapperDir, name) {
7734
+ if (name.startsWith("@")) {
7735
+ const [scope, pkg] = name.split("/");
7736
+ if (!scope || !pkg || basename(dirname3(wrapperDir)) !== scope) return void 0;
7737
+ const prefix2 = `${pkg}@`;
7738
+ const base2 = basename(wrapperDir);
7739
+ return base2.startsWith(prefix2) ? base2.slice(prefix2.length) : void 0;
7740
+ }
7741
+ const prefix = `${name}@`;
7742
+ const base = basename(wrapperDir);
7743
+ return base.startsWith(prefix) ? base.slice(prefix.length) : void 0;
7744
+ }
7681
7745
  function isAutoUpdatableSpec(spec) {
7682
7746
  const value = spec.trim();
7683
7747
  if (!value) return false;