Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fd8e9b
Stop treating a directory as a snapshot because of its name
daniel-rossier Oct 12, 2026
8475e77
Validate the final state even when only the terminal changed it
daniel-rossier Oct 12, 2026
4298909
Give the sidebar the same mark as the landing logo
daniel-rossier Oct 12, 2026
16f1195
Never let a model mutation change git metadata
daniel-rossier Oct 12, 2026
e5ce906
Keep a protected target protected whatever primitive is used
daniel-rossier Oct 12, 2026
64e40a1
Judge a launched command by what it runs
daniel-rossier Oct 13, 2026
c7ca67e
Let a git command keep its own repository's records
daniel-rossier Oct 13, 2026
c2f93ac
Refuse fuzzy edits that rewrite literal diff markers
daniel-rossier Oct 31, 2026
d474a78
Stop a turn that repeats the same successful call
daniel-rossier Oct 31, 2026
25c0acd
Size the sandbox memory cap for a kernel build, and say when it kills
daniel-rossier Oct 31, 2026
c1dece6
Keep product names out of the sandbox-limit comments
daniel-rossier Oct 31, 2026
ee687e2
Let a bounded command run past the turn's silence watchdog
daniel-rossier Oct 31, 2026
d07a7f9
Pin the coding core to core-v0.3.1, v0.3.0's core with the patch guard
daniel-rossier Oct 31, 2026
c808589
Return what a limit-killed command printed before the kill
daniel-rossier Oct 31, 2026
62c1c6a
Count the scope's SIGTERM as a limit kill: systemd stops an OOM-kille…
daniel-rossier Oct 31, 2026
ad11e82
Harden the refusal policy: control-plane metadata, interpreters, fals…
daniel-rossier Nov 2, 2026
2ad86bf
Policy regressions minimised from the Qwen3.8 characterization
daniel-rossier Nov 2, 2026
d1fa93d
Session cleanup by provenance; a test runner is no authority
daniel-rossier Nov 2, 2026
5961b52
Session-cleanup and test-runner regressions
daniel-rossier Nov 2, 2026
d27503f
Close the routes the V2 screen found open
daniel-rossier Nov 3, 2026
f16a4eb
HARDENED-V3 regressions
daniel-rossier Nov 3, 2026
dcb1505
The attach state is the attach's; a build removes only its own output
daniel-rossier Nov 3, 2026
7d4e654
HARDENED-V4 regressions
daniel-rossier Nov 3, 2026
7b552b8
A component's own ignore rules mark what its build generates
daniel-rossier Nov 3, 2026
6a70bce
A request in a project of a declared family is about its tree
daniel-rossier Nov 4, 2026
3cb8028
Trust an attach refresh only after a clean reconstruction
daniel-rossier Nov 5, 2026
5328eeb
Pin only the pristine copy a build itself made
daniel-rossier Nov 5, 2026
d05844d
Find the build-output rules of a project that has built nothing
daniel-rossier Nov 5, 2026
3bb7bd3
Merge the production line: core pin, refusal hardening, attach checks
daniel-rossier Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions client/agent/patch_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""Refuse the fuzzy matches that rewrite literal text instead of whitespace.

The Hermes matching chain (hermes/fuzzy_match.py, kept unmodified) falls back
to strategies that strip leading whitespace or accept lines that are only
similar. In a unified diff the first column is a marker, not indentation: a
'+' line sent without its '+', or a ' ' context line sent as an empty one,
matched anyway, and the replacement dropped or grafted the markers -- a
corrupt patch reported as a successful edit. The same similarity let a model's
diff-prefixed text match plain C lines and write the '+' into the source.

Two rules, applied only when the chain matched through a non-exact strategy:
diff content (hunk headers plus file headers) is matched exactly or not at
all, and no aligned line pair may differ by a leading '+' or '-'. Both refuse
the edit; nothing is repaired.
"""

from __future__ import annotations

import re

from .hermes import fuzzy_match

DIFF_HUNK = re.compile(r"^@@ -\d+(,\d+)? \+\d+(,\d+)? @@", re.MULTILINE)
DIFF_FILE = re.compile(r"^(---|\+\+\+) \S", re.MULTILINE)

DIFF_EXACT_ONLY = (
"This file is a unified diff: old_string must match it exactly, first-column "
"markers included (' ' for context, '+' for added, '-' for removed lines). "
"Re-read the lines and copy them verbatim, or edit the source tree and "
"regenerate the patch with the project's workflow.")

MARKER_DRIFT = (
"old_string only resembles the file here: line {line} of old_string starts "
"with {pattern!r} where the file's line starts with {content!r}. A leading "
"'+' or '-' is text, not indentation; copy the lines exactly as the file "
"has them.")


def is_unified_diff(content: str) -> bool:
return bool(DIFF_HUNK.search(content) and DIFF_FILE.search(content))


def _lead(line: str) -> str:
return line.lstrip(" \t")[:1]


def marker_drift(content: str, matches: list, old_string: str) -> str | None:
"""The refusal for a match whose lines differ by a leading +/- marker."""
pattern_lines = old_string.split("\n")

for start, end in matches:
for number, (pattern, found) in enumerate(zip(pattern_lines, content[start:end].split("\n")), 1):
a, b = _lead(pattern), _lead(found)

if a != b and {a, b} & {"+", "-"}:
return MARKER_DRIFT.format(line=number, pattern=a, content=b)
return None


def find_and_replace(content: str, old_string: str, new_string: str,
replace_all: bool = False):
"""fuzzy_find_and_replace with the two literal-text rules on top."""
new_content, count, strategy, error = fuzzy_match.fuzzy_find_and_replace(
content, old_string, new_string, replace_all)

if error or not count or strategy == "exact":
return new_content, count, strategy, error

if is_unified_diff(content):
return content, 0, None, DIFF_EXACT_ONLY

matches = getattr(fuzzy_match, f"_strategy_{strategy}")(content, old_string)
refusal = marker_drift(content, matches, old_string)

if refusal:
return content, 0, None, refusal
return new_content, count, strategy, error
5 changes: 3 additions & 2 deletions client/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
import stat
import subprocess

from . import patch_guard
from .hermes.ansi_strip import strip_ansi
from .hermes.binary_extensions import has_binary_extension
from .hermes.exit_codes import _interpret_exit_code
from .hermes.fuzzy_match import format_no_match_hint, fuzzy_find_and_replace, is_already_applied
from .hermes.fuzzy_match import format_no_match_hint, is_already_applied
from .hermes.file_helpers import (
LINTERS_INPROC, _FAIL_CLOSED_INPROC_EXTS, _READ_DEDUP_STATUS_MESSAGE,
_detect_line_ending, _is_internal_file_tool_content, _is_likely_binary_bytes,
Expand Down Expand Up @@ -882,7 +883,7 @@ def patch(state: dict, display: str, resolved: str, old_string, new_string,
raw = handle.read()

content, _ = _strip_bom(raw)
new_content, match_count, _strategy, error = fuzzy_find_and_replace(
new_content, match_count, _strategy, error = patch_guard.find_and_replace(
content, old_string, new_string, replace_all)

if error or match_count == 0:
Expand Down
9 changes: 7 additions & 2 deletions client/cli/rag_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from runtime.tracing import EventStatus, EventType, new_task_id
from runtime.working_state import StateEventType, WorkingState
from context.context_engine import ContextLayer
from context import workspace_context
from context.workspace_context import project_families
from runtime.compaction import CompactionMode, CompactionPolicy
from runtime.agent_context import AgentContext
Expand Down Expand Up @@ -966,12 +967,16 @@ def read_user_input():
# its own words is answered from those words and the document.
bound_turn = bool(turn_binding)

projects = load_projects()
project_bound = workspace_context.project_bound(
registered=session_workspace.PROJECT in projects,
spec=projects.get(session_workspace.PROJECT))
said_before = next((message["content"] for message in reversed(hist)
if message["role"] == "user"), "")
prior_scope = answer_scope.of(answer_scope.spoken_part(said_before),
standard_bound=bound_turn)
standard_bound=bound_turn, project_bound=project_bound)
turn_scope = answer_scope.of(user_input, prior=prior_scope,
standard_bound=bound_turn)
standard_bound=bound_turn, project_bound=project_bound)
hist = answer_scope.carried(
hist, turn_scope, standard_bound=bound_turn,
self_contained=answer_scope.self_contained(user_input))
Expand Down
Loading
Loading