@eduardo191labs/opencode-free-pi 0.7.6 → 0.7.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
@@ -168,6 +168,10 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
168
168
  omitir: leer antes de editar, ejecutar las comprobaciones de verdad, no
169
169
  afirmar que algo pasó si no se ejecutó, reutilizar las decisiones y rutas ya
170
170
  establecidas en la conversación y no fingir que se compactó el contexto.
171
+ Además, cuando una herramienta falla por un motivo que el modelo repite (un
172
+ heredoc rechazado por el scanner del shell, un `edit` con cadenas idénticas o
173
+ con un `oldString` ambiguo), el error que recibe añade el siguiente paso
174
+ concreto en lugar de dejar solo el mensaje técnico.
171
175
  - **Compactación con instrucciones**: el resumen de compactación recibe además
172
176
  un bloque que le pide conservar requisitos sin resolver, decisiones y sus
173
177
  motivos, rutas y símbolos exactos, comandos con su resultado, errores y
@@ -505,9 +505,55 @@ async function registerToolHooks(ctx, deps, registrations) {
505
505
  status: event.status,
506
506
  ...(event.status === "completed" ? { result: event.result } : {}),
507
507
  });
508
+ nudgeFailedTool(deps, event);
508
509
  replaceUnsupportedImages(deps, event);
509
510
  }));
510
511
  }
512
+ /**
513
+ * Adds the concrete next step to a tool failure the free models repeat.
514
+ *
515
+ * The scan of a week of sessions shows the same failures over and over: the
516
+ * portable shell scanner rejects a heredoc or a nested-quote one-liner (72
517
+ * times), `edit` gets identical strings (12) or an ambiguous `oldString` (8).
518
+ * The model reads the bare error and often repeats the call. The hint is short
519
+ * and only goes to free-pi sessions; other providers keep their own messages.
520
+ */
521
+ function nudgeFailedTool(deps, event) {
522
+ if (event.status !== "error")
523
+ return;
524
+ if (!isFreePiSession(deps, event.sessionID))
525
+ return;
526
+ const error = event.error;
527
+ if (!error || typeof error !== "object")
528
+ return;
529
+ const message = typeof error.message === "string" ? error.message : "";
530
+ if (!message)
531
+ return;
532
+ let hint = "";
533
+ if (message.includes("Portable shell scanner cannot analyze command")) {
534
+ hint =
535
+ " Write the script to a file with the write tool and run that file; on Windows use PowerShell cmdlets instead of cmd syntax.";
536
+ }
537
+ else if (/No changes to apply: oldString and newString are identical/i.test(message)) {
538
+ hint =
539
+ " Change the replacement text: oldString and newString must differ. Re-read the line you want to change first.";
540
+ }
541
+ else if (/Found \d+ matches? for oldString/i.test(message)) {
542
+ hint =
543
+ " Include enough surrounding lines so oldString matches exactly once, or set replaceAll when every occurrence must change.";
544
+ }
545
+ else if (/has not been read yet|read it before/i.test(message)) {
546
+ hint = " Read the file with the read tool in this turn before editing it.";
547
+ }
548
+ if (!hint)
549
+ return;
550
+ try {
551
+ error.message = `${message}${hint}`;
552
+ }
553
+ catch {
554
+ // A frozen error still reaches the model unchanged; the hint is best effort.
555
+ }
556
+ }
511
557
  /**
512
558
  * Models whose upstream accepts images get them natively, so a `read` that
513
559
  * returns a picture must keep the file part. Text-only models would turn it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduardo191labs/opencode-free-pi",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "Ad-supported free-pi provider plugin for OpenCode on Windows, Linux, macOS and Termux",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -689,11 +689,49 @@ async function registerToolHooks(
689
689
  status: event.status,
690
690
  ...(event.status === "completed" ? { result: event.result } : {}),
691
691
  });
692
+ nudgeFailedTool(deps, event);
692
693
  replaceUnsupportedImages(deps, event);
693
694
  }),
694
695
  );
695
696
  }
696
697
 
698
+ /**
699
+ * Adds the concrete next step to a tool failure the free models repeat.
700
+ *
701
+ * The scan of a week of sessions shows the same failures over and over: the
702
+ * portable shell scanner rejects a heredoc or a nested-quote one-liner (72
703
+ * times), `edit` gets identical strings (12) or an ambiguous `oldString` (8).
704
+ * The model reads the bare error and often repeats the call. The hint is short
705
+ * and only goes to free-pi sessions; other providers keep their own messages.
706
+ */
707
+ function nudgeFailedTool(deps: Deps, event: any): void {
708
+ if (event.status !== "error") return;
709
+ if (!isFreePiSession(deps, event.sessionID)) return;
710
+ const error = event.error;
711
+ if (!error || typeof error !== "object") return;
712
+ const message = typeof error.message === "string" ? error.message : "";
713
+ if (!message) return;
714
+ let hint = "";
715
+ if (message.includes("Portable shell scanner cannot analyze command")) {
716
+ hint =
717
+ " Write the script to a file with the write tool and run that file; on Windows use PowerShell cmdlets instead of cmd syntax.";
718
+ } else if (/No changes to apply: oldString and newString are identical/i.test(message)) {
719
+ hint =
720
+ " Change the replacement text: oldString and newString must differ. Re-read the line you want to change first.";
721
+ } else if (/Found \d+ matches? for oldString/i.test(message)) {
722
+ hint =
723
+ " Include enough surrounding lines so oldString matches exactly once, or set replaceAll when every occurrence must change.";
724
+ } else if (/has not been read yet|read it before/i.test(message)) {
725
+ hint = " Read the file with the read tool in this turn before editing it.";
726
+ }
727
+ if (!hint) return;
728
+ try {
729
+ error.message = `${message}${hint}`;
730
+ } catch {
731
+ // A frozen error still reaches the model unchanged; the hint is best effort.
732
+ }
733
+ }
734
+
697
735
  /**
698
736
  * Models whose upstream accepts images get them natively, so a `read` that
699
737
  * returns a picture must keep the file part. Text-only models would turn it