diff --git a/README.md b/README.md index d6d6b314e9..2f62c61617 100644 --- a/README.md +++ b/README.md @@ -613,6 +613,7 @@ Issues (2) | `SKILLSPECTOR_OUTPUT_LANGUAGE` | Short, single-line language label (letters, numbers, spaces, `_`, or `-`; maximum 64 characters) for human-readable LLM finding text such as messages, explanations, and remediation. Rule IDs, severity values, paths, code, and other machine-readable values remain unchanged. Unset, blank, or invalid values preserve the default output language. | Optional | | `SKILLSPECTOR_TEMPERATURE` | Optional sampling temperature from `0` to `1` for hosted providers. Unset or blank preserves the provider default. Lower values can reduce run-to-run variation but do not guarantee identical output. | Optional | | `SKILLSPECTOR_SEED` | Optional integer sampling seed for OpenAI-compatible and Azure OpenAI providers. Other hosted providers and CLI providers do not receive it. Provider support remains model-dependent. | Optional | +| `SKILLSPECTOR_COMPACT_PROMPTS` | Opt-in compact line numbering in LLM prompts: numbered lines render as `L1:`, `L2:` instead of zero-padded `L01:`, `L02:`. Accepted truthy values are `1`, `true`, and `yes` (case-insensitive; surrounding whitespace is trimmed). Unset or any other value keeps the default zero-padded format. | Optional | | `ANTHROPIC_API_KEY` | Credential for the Anthropic provider (`SKILLSPECTOR_PROVIDER=anthropic`). | Required for LLM analysis when `SKILLSPECTOR_PROVIDER=anthropic` | | `ANTHROPIC_BASE_URL` | Override the native Anthropic endpoint (default: `https://api.anthropic.com`). | Optional | | `ANTHROPIC_PROXY_ENDPOINT_URL` | Full endpoint URL for the Anthropic proxy provider (Vertex-style raw-predict). | Required when `SKILLSPECTOR_PROVIDER=anthropic_proxy` | diff --git a/src/skillspector/llm_analyzer_base.py b/src/skillspector/llm_analyzer_base.py index b3e0aae03c..1058538c04 100644 --- a/src/skillspector/llm_analyzer_base.py +++ b/src/skillspector/llm_analyzer_base.py @@ -592,6 +592,8 @@ def number_lines(content: str, start_line: int = 1) -> str: lines = content.splitlines() if not lines: return "" + if os.environ.get("SKILLSPECTOR_COMPACT_PROMPTS", "").strip().lower() in {"1", "true", "yes"}: + return "\n".join(f"L{start_line + i}: {line}" for i, line in enumerate(lines)) end = start_line + len(lines) - 1 width = len(str(end)) return "\n".join(f"L{start_line + i:0>{width}}: {line}" for i, line in enumerate(lines)) diff --git a/tests/nodes/test_llm_analyzer_base.py b/tests/nodes/test_llm_analyzer_base.py index 84093cab85..aa22063bc1 100644 --- a/tests/nodes/test_llm_analyzer_base.py +++ b/tests/nodes/test_llm_analyzer_base.py @@ -306,6 +306,36 @@ def test_zero_padding(self) -> None: assert result.startswith("L01: line0") assert "L11: line10" in result + def test_compact_prompts_disable_zero_padding(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("SKILLSPECTOR_COMPACT_PROMPTS", "true") + lines = "\n".join(f"line{i}" for i in range(11)) + assert number_lines(lines).startswith("L1: line0") + + @pytest.mark.parametrize("value", ["1", "true", "TRUE", "yes", "Yes", " true "]) + def test_compact_prompts_normalized_truthy_values( + self, monkeypatch: pytest.MonkeyPatch, value: str + ) -> None: + monkeypatch.setenv("SKILLSPECTOR_COMPACT_PROMPTS", value) + lines = "\n".join(f"line{i}" for i in range(11)) + assert number_lines(lines).startswith("L1: line0") + + @pytest.mark.parametrize("value", ["0", "false", "no", ""]) + def test_compact_prompts_falsy_values_keep_default( + self, monkeypatch: pytest.MonkeyPatch, value: str + ) -> None: + monkeypatch.setenv("SKILLSPECTOR_COMPACT_PROMPTS", value) + lines = "\n".join(f"line{i}" for i in range(11)) + result = number_lines(lines) + assert result.startswith("L01: line0") + assert "L11: line10" in result + + def test_compact_prompts_unset_keeps_default(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("SKILLSPECTOR_COMPACT_PROMPTS", raising=False) + lines = "\n".join(f"line{i}" for i in range(11)) + result = number_lines(lines) + assert result.startswith("L01: line0") + assert "L11: line10" in result + # --------------------------------------------------------------------------- # LLMAnalyzerBase.build_prompt (default implementation)