refactor(scripts): restructured edit-mode fallbacks to ignore strict mode

- Removed PI_STRICT_EDIT_MODE gating from edit-mode resolution so model fallbacks now always apply.
- Stopped injecting PI_STRICT_EDIT_MODE in edit-benchmark.py and rate-edit-tool.py execution environments.
- Removed PI_STRICT_EDIT_MODE from environment-variable documentation and strict-mode test coverage.
This commit is contained in:
can1357
2026-05-02 04:33:52 +02:00
parent 1a95e93ac7
commit 2826ec2ea0
5 changed files with 9 additions and 23 deletions
-1
View File
@@ -287,7 +287,6 @@ Extra conditional behavior:
| `OLLAMA_BASE_URL` | Default implicit Ollama discovery base URL override (`http://127.0.0.1:11434` if unset) |
| `LLAMA_CPP_BASE_URL` | Default implicit Llama.cpp discovery base URL override (`http://127.0.0.1:8080` if unset) |
| `PI_EDIT_VARIANT` | Forces edit tool variant when valid (`patch`, `replace`, `hashline`, `atom`, `vim`, `apply_patch`) |
| `PI_STRICT_EDIT_MODE` | If truthy, disables automatic edit-mode fallback |
| `PI_FORCE_IMAGE_PROTOCOL` | Forces supported image protocol (`kitty`, `iterm2`/`iterm`, `sixel`, `none`) where used |
| `PI_ALLOW_SIXEL_PASSTHROUGH` | Allows SIXEL passthrough when `PI_FORCE_IMAGE_PROTOCOL=sixel` |
| `PI_NO_PTY` | If `1`, disables interactive PTY path for bash tool |
+6 -8
View File
@@ -1,4 +1,4 @@
import { $env, $flag } from "@oh-my-pi/pi-utils";
import { $env } from "@oh-my-pi/pi-utils";
export type EditMode = "replace" | "patch" | "hashline" | "vim" | "apply_patch" | "atom";
@@ -38,13 +38,11 @@ export function resolveEditMode(session: EditModeSessionLike): EditMode {
const envMode = normalizeEditMode($env.PI_EDIT_VARIANT);
if (envMode) return envMode;
if (!$flag("PI_STRICT_EDIT_MODE")) {
if (activeModel?.includes("spark")) return "apply_patch";
if (activeModel?.includes("nano")) return "replace";
if (activeModel?.includes("mini")) return "replace";
if (activeModel?.includes("haiku")) return "replace";
if (activeModel?.includes("flash")) return "replace";
}
if (activeModel?.includes("spark")) return "apply_patch";
if (activeModel?.includes("nano")) return "replace";
if (activeModel?.includes("mini")) return "replace";
if (activeModel?.includes("haiku")) return "replace";
if (activeModel?.includes("flash")) return "replace";
const settingsMode = normalizeEditMode(String(session.settings.get("edit.mode") ?? ""));
return settingsMode ?? DEFAULT_EDIT_MODE;
+2 -11
View File
@@ -2,7 +2,6 @@ import { afterEach, describe, expect, test } from "bun:test";
import { type EditMode, type EditModeSessionLike, resolveEditMode } from "@oh-my-pi/pi-coding-agent/utils/edit-mode";
const originalEditVariant = Bun.env.PI_EDIT_VARIANT;
const originalStrictEditMode = Bun.env.PI_STRICT_EDIT_MODE;
function restoreEnv(): void {
if (originalEditVariant === undefined) {
@@ -10,11 +9,6 @@ function restoreEnv(): void {
} else {
Bun.env.PI_EDIT_VARIANT = originalEditVariant;
}
if (originalStrictEditMode === undefined) {
delete Bun.env.PI_STRICT_EDIT_MODE;
} else {
Bun.env.PI_STRICT_EDIT_MODE = originalStrictEditMode;
}
}
function createSession(args: {
@@ -38,26 +32,23 @@ describe("resolveEditMode", () => {
test("defaults Spark models to apply_patch mode", () => {
delete Bun.env.PI_EDIT_VARIANT;
delete Bun.env.PI_STRICT_EDIT_MODE;
expect(resolveEditMode(createSession({ activeModel: "openai-codex/gpt-5.3-codex-spark" }))).toBe("apply_patch");
});
test("keeps explicit model variants ahead of Spark fallback", () => {
delete Bun.env.PI_EDIT_VARIANT;
delete Bun.env.PI_STRICT_EDIT_MODE;
expect(
resolveEditMode(createSession({ activeModel: "openai-codex/gpt-5.3-codex-spark", modelVariant: "replace" })),
).toBe("replace");
});
test("strict edit mode disables Spark fallback", () => {
test("keeps model-specific fallbacks ahead of settings mode", () => {
delete Bun.env.PI_EDIT_VARIANT;
Bun.env.PI_STRICT_EDIT_MODE = "1";
expect(
resolveEditMode(createSession({ activeModel: "openai-codex/gpt-5.3-codex-spark", settingsMode: "hashline" })),
).toBe("hashline");
).toBe("apply_patch");
});
});
+1 -1
View File
@@ -58,7 +58,7 @@ def build_spec(variant: str) -> BenchmarkSpec:
description=f"Benchmark edit tool in {variant} mode across models with simple edit tasks.",
workspace_prefix=f"{variant}-benchmark",
tools=("edit", "read"),
env={"PI_EDIT_VARIANT": variant, "PI_STRICT_EDIT_MODE": "1"},
env={"PI_EDIT_VARIANT": variant},
initial_prompt=prompt,
retry_instruction=retry,
)
-2
View File
@@ -1632,7 +1632,6 @@ def run_model_sync(
executable=omp_bin,
model=model,
cwd=workspace,
env={"PI_STRICT_EDIT_MODE": "1"},
thinking="high",
tools=TOOL_WHITELIST,
no_skills=True,
@@ -1852,7 +1851,6 @@ def run_oracle_review_sync(
executable=omp_bin,
model=model,
cwd=results_dir,
env={"PI_STRICT_EDIT_MODE": "1"},
thinking="high",
tools=(),
no_skills=True,