diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6bc587..c035cf5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- rule-hook now reads `git > out commit -m x` as one git commit, as the shell runs it. A redirect used to split a command in two, so such a commit escaped `commit-one-line`, `round-title-counts` and `todo-rank-check`. - `larv-review needs-scoring-run` now calls a scoring run for the release `chunk-preflight` names as next, not for the earliest release in the plan. It also counts a change as unreleased the way `chunk-preflight` does: an entry under `CHANGELOG.md` → `## Unreleased`, or, where there is no such section, a commit after the newest `v*` tag (any commit when there is none). Before, a chunk that moved the next release's last items to a later release without shipping them called a scoring run, while `chunk-preflight` called that release unplanned. - README → Install now says that every machine taking this checkout must be a sandbox with no direct access to a production environment, since `settings.json` runs Claude Code in auto mode with the dangerous-mode prompt skipped. Before, it asked for a sandbox only for `loop-claude`. diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 9f1071fc..ec245253 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -20,7 +20,7 @@ from rule_hook.override_log import LogLine, parsed_entry, this_chunks from rule_hook.reviewer_rung import reviewer_breaches from rule_hook.git import git as rule_hook_git from model_routing.ladder import Rung -from shell_command import simple_commands +from shell_command import segments, simple_commands HOOK = pathlib.Path(__file__).resolve().parents[1] / "rule-hook" # Built from parts, so this file carries no attribution of its own. @@ -75,6 +75,20 @@ class Commits(unittest.TestCase): def test_a_line_that_does_not_parse_hides_only_itself(self): self.assertEqual(len(committed("echo 'open\ngit commit -m a")), 1) + def test_a_redirect_keeps_its_command_s_words_together(self): + self.assertEqual(segments("echo hi > f arg"), [["echo", "hi", "arg"]]) + for redirect in [">", ">>", "<", "<<<", "<>", ">&", "<&", ">|", "&>", "&>>"]: + with self.subTest(redirect): + self.assertEqual(committed(f"git {redirect} /tmp/x commit -m hi"), [Commit("/r", ["hi"], False)]) + self.assertEqual(committed("git commit >&2 -m hi 2>&1"), [Commit("/r", ["hi"], False)]) + self.assertEqual(committed("> out git commit -m hi"), [Commit("/r", ["hi"], False)]) + + def test_a_separator_glued_to_a_redirect_still_ends_the_command(self): + self.assertEqual(segments("echo a > f; echo b | cat &> g\nls"), [["echo", "a"], ["echo", "b"], ["cat"], ["ls"]]) + for command in ["echo a &f git commit -m hi"]: + with self.subTest(command): + self.assertEqual(committed(command), [Commit("/r", ["hi"], False)]) + class CommandBreaches(unittest.TestCase): def test_one_line_passes(self): diff --git a/bin/shell_command.py b/bin/shell_command.py index 6fe84ce8..294bd554 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -7,6 +7,8 @@ import shlex HEREDOC = re.compile(r"<<-?[ \t]*([\"']?)([A-Za-z_]\w*)\1[^\n]*\n.*?^[ \t]*\2[ \t]*$", re.DOTALL | re.MULTILINE) ASSIGNMENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=") OPERATOR = set("\n();&|<>") +# A token that is only a redirect: the command's words go on after its target. `&<` is not one: it is a `&` that ends the command, then a `<`. +REDIRECT = re.compile(r"&>>?|[<>]+[&|]?") # A quoted string or an escape is taken whole, so a # inside one starts no comment; a comment starts a word. PIECE = re.compile(r"""'[^']*'|"(?:\\.|[^"\\])*"|\\.|(? list[Simple]: def segments(command: str) -> list[list[str]]: - """The command's simple commands as lists of words, split at ; & | ( ) < > and line breaks, without redirect targets. Shell forms it does not parse: + """The command's simple commands as lists of words, split at ; & | ( ) and line breaks, without redirect targets. Shell forms it does not parse: - a quoted string is one word, so `bash -c "git commit"` and `echo "$(git commit)"` hide the inner command; - a backtick substitution stays inside its words, while `$(git commit)` outside quotes splits into the `$` and a command of its own; - a keyword or a brace opens its command's words, so `then git commit` reads as the command `then`; - - a redirect splits a command in two, so `git > out commit` reads as `git` and `commit`; - - `<(...)` and `<<<` read as redirects, so the word after them is dropped as the target; + - `<(...)` and `>(...)` end the command, and the first word inside them is dropped as a redirect target, so `tee >(git commit)` hides the commit; - a file descriptor before a redirect, as in `2>&1`, stays a word; - a heredoc's body is dropped; - variables, aliases and functions are not expanded; @@ -49,8 +50,11 @@ def segments(command: str) -> list[list[str]]: for token in tokens: if target: target = False - elif set(token) <= OPERATOR and token: + elif REDIRECT.fullmatch(token): # A redirect's target is not an operand. + target = True + elif set(token) <= OPERATOR and token: + # A separator, or a redirect glued to one as in `;>f`, `&" in token found.append([]) elif found[-1] or not ASSIGNMENT.match(token): diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 0a90924b..0d90e9e9 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -762,3 +762,7 @@ Read most (opens and searches): ## Reading cost, chunk e78792eec4a6, finished 2026-10-22T00:08:00Z 71637 new input tokens before the first commit. + +## Reading cost, chunk 6b16b3b2e832, finished 2026-10-22T00:24:58Z + +61875 new input tokens before the first commit. diff --git a/todo.md b/todo.md index 070eeace..f44555a2 100644 --- a/todo.md +++ b/todo.md @@ -13,7 +13,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| | 170 | 0.4.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 10 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.9 | -| 154 | 0.4.0 | | defect | **Have `bin/shell_command.py`'s `segments` keep a command's words together across a redirect, so `git > out commit` reads as one git commit.** | 1 | 1 | 3 | 3 | 2 | 1.1 by 6 | 8.4 | | 186 | 0.4.0 | | | **Point every file a session parks outside its checkout, such as the comprehension panel's detached worktree and a build probe's output, at a folder a headless session has, since loop-claude's sessions have no scratchpad.** | 1 | 2 | 2 | 3 | 2 | 1.1 by 3, 1.5 by 2 | 6.8 | | 198 | 0.4.0 | | decision | **Count, per finished chunk, the findings that arose from misreading code that had already shipped, so code health's counter-signal shows.** | 3 | 2 | 2 | 5 | 5 | code health by 3, 1.1 by 2 | 6.2 | | 59 | 0.4.0 | | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 2 | 1 | 3 | 4 | 3 | 1.4 by 6 | 6.0 | @@ -81,10 +80,6 @@ `docs/decisions.md` → `routing: one ladder…` calls the steps lilleman approved on 2026-10-16 a first guess. Once 10 chunks that each shipped one item scored with L, E and I have merged, read `score-outcomes`' rank correlations for L, E and I and the routed-chunks table of `routing-figures.md`, and propose new steps to lilleman, whose call they are. -### 154. Have `bin/shell_command.py`'s `segments` keep a command's words together across a redirect, so `git > out commit` reads as one git commit. - -`segments('echo hi > f arg')` returns `arg` as a command of its own, and `segments('git > /tmp/x commit -m hi')` returns `git` and `commit -m hi` apart, though the shell runs one `git commit`. rule-hook's commit rules read the commands `segments` finds, so such a commit escapes `commit-one-line`, `no-ai-attribution`, `round-title-counts` and `todo-rank-check`. The comprehension seats' scoring run in PR #280 found it. - ### 186. Point every file a session parks outside its checkout, such as the comprehension panel's detached worktree and a build probe's output, at a folder a headless session has, since loop-claude's sessions have no scratchpad. `skills/comprehension-panel/SKILL.md` puts the base version's detached worktree "in your scratchpad", and `CLAUDE.md` → "Working with the codebase" lets a build-probing subagent write "only to the session scratchpad". A probe on 2026-10-18 found no `scratchpad_dir` in a headless `claude -p` session's hook input, and neither the session nor its subagent knew a scratchpad path. larv-review now parks its reports and votes file in the chunk's review folder under `~/.local/state/larv-review/`, per `docs/decisions.md` → `review: each reviewer under agents/ writes its full report into the chunk's review folder`. Found by the architecture review of PR #310.