opencode-immune 1.0.86 → 1.0.87

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.
@@ -5888,7 +5888,7 @@ Router action: retry the SAME pipeline slot once by creating a NEW Task call to
5888
5888
  if (state.lastEditAttempt) {
5889
5889
  const edit = state.lastEditAttempt;
5890
5890
  output.system.push(
5891
- `[Edit Error Recovery] Previous edit failed for "${edit.filePath}". The oldString was not found in the file. Read the file first to get the correct content, then retry the edit with the exact oldString from the file.`
5891
+ `[File Modification Recovery] Previous ${edit.tool} operation failed for "${edit.filePath}". Read the file first to get the correct content, then retry with the available file modification tool. If using edit, use the exact oldString from the file. If using apply_patch, build the patch from the current file content.`
5892
5892
  );
5893
5893
  state.lastEditAttempt = null;
5894
5894
  }
@@ -5897,19 +5897,37 @@ Router action: retry the SAME pipeline slot once by creating a NEW Task call to
5897
5897
  }
5898
5898
  };
5899
5899
  }
5900
+ function isFileModificationTool(tool) {
5901
+ return tool === "edit" || tool === "write" || tool === "apply_patch";
5902
+ }
5903
+ function getPatchPath(patchText) {
5904
+ const match = patchText.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/m);
5905
+ return match?.[1]?.trim() || "patch";
5906
+ }
5907
+ function getFileModificationPath(tool, args) {
5908
+ if (tool === "apply_patch") return getPatchPath(args?.patchText ?? "");
5909
+ return args?.filePath ?? "unknown";
5910
+ }
5911
+ function getFileModificationContent(tool, args) {
5912
+ if (tool === "edit") return args?.newString ?? "";
5913
+ if (tool === "write") return args?.content ?? "";
5914
+ if (tool === "apply_patch") return args?.patchText ?? "";
5915
+ return "";
5916
+ }
5900
5917
  function createRalphLoopToolAfter(state) {
5901
5918
  return async (input, output) => {
5902
- if (input.tool !== "edit") return;
5919
+ if (!isFileModificationTool(input.tool)) return;
5903
5920
  const outputText = typeof output.output === "string" ? output.output : "";
5904
5921
  if (outputText.includes("oldString not found") || outputText.includes("Found multiple matches")) {
5905
5922
  state.lastEditAttempt = {
5906
- filePath: input.args?.filePath ?? "unknown",
5923
+ filePath: getFileModificationPath(input.tool, input.args),
5907
5924
  oldString: input.args?.oldString ?? "",
5908
- newString: input.args?.newString ?? "",
5925
+ newString: getFileModificationContent(input.tool, input.args),
5926
+ tool: input.tool,
5909
5927
  timestamp: Date.now()
5910
5928
  };
5911
5929
  pluginLog.warn(
5912
- `[opencode-immune] Ralph Loop: Edit failed for "${state.lastEditAttempt.filePath}". Recovery hint will be injected in next system transform.`
5930
+ `[opencode-immune] Ralph Loop: ${input.tool} failed for "${state.lastEditAttempt.filePath}". Recovery hint will be injected in next system transform.`
5913
5931
  );
5914
5932
  } else {
5915
5933
  state.lastEditAttempt = null;
@@ -5951,8 +5969,8 @@ var EMOJI_PATTERN = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\
5951
5969
  var TODO_PATTERN = /\b(TODO|FIXME|HACK|XXX)\b/i;
5952
5970
  function createCommentCheckerToolAfter(state) {
5953
5971
  return async (input, _output) => {
5954
- if (input.tool !== "edit" && input.tool !== "write") return;
5955
- const content = input.tool === "edit" ? input.args?.newString ?? "" : input.args?.content ?? "";
5972
+ if (!isFileModificationTool(input.tool)) return;
5973
+ const content = getFileModificationContent(input.tool, input.args);
5956
5974
  if (!content) return;
5957
5975
  if (EMOJI_PATTERN.test(content)) {
5958
5976
  pluginLog.warn(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-immune",
3
- "version": "1.0.86",
3
+ "version": "1.0.87",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin: session recovery, auto-retry, multi-cycle automation, context monitoring",
6
6
  "exports": {