Skip to content

Commit d0420f5

Browse files
psjg-claudeclaude
authored andcommitted
feat(upstream): search the commits since the reported version
Keyword searches miss a fix merged after the release the user ran: T3 Code #27706 fixed the reported bug but sat unreleased behind v0.1.9, and the draft theorised on main. `search --history TAG..DEFAULT --clone DIR --paths ...` runs git log over that range, turns every #N in a subject into a hit that must be marked, and an issue or PR can no longer leave the search step without it. Assisted-By: claude-opus-5-5 Harness: claude-code Session-Id: 590da241-8900-4d41-9a97-95cc3e402d71 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent af3176d commit d0420f5

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

‎skills/upstream/SKILL.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ $U init OWNER/REPO --channel issue --user @HANDLE # comment: --channel comment
7979
$U rules # or: rules --local CLONE
8080
$U rules classify --outcome welcome --form "..." # + --security / --no-mentions
8181
$U search --keywords "..." # then: search mark N related|unrelated|duplicate "why"
82+
$U search --history v1.2..origin/main --clone DIR --paths F... # PR numbers in later commits become hits
8283
$U claim add --text "<sentence as posted>" --cmd "<command>" --permalink URL
8384
$U env
8485
$U draft check draft.md
@@ -202,7 +203,8 @@ list), the handle from the user's instructions.
202203
ends the flow: comment there (`init --channel comment --thread N` in a new
203204
`--workdir`) or tell the user. Before any root-cause theory, pin the
204205
version the user ran and diff it against the default branch:
205-
`git log <reported-tag>..origin/<default> -- <suspect files>`. If the
206+
`search --history <reported-tag>..origin/<default> --clone DIR --paths
207+
<suspect files>`; every `#N` in those commits becomes a hit to mark. If the
206208
suspect lines changed, reproduce on the default branch first; a symptom
207209
gone there is "fixed, unreleased" (tell the user which release has it),
208210
not a draft. Reading the code of the wrong version produces a confident,

‎skills/upstream/scripts/test_upstream.py‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def up(self, *args, ok=True) -> str:
7272
self.assertEqual(p.returncode == 0, ok, f"upstream.py {' '.join(args)} -> exit {p.returncode}\n{out}")
7373
return out
7474

75+
def history(self) -> list[str]:
76+
return ["--history", f"{self.sha}..HEAD", "--clone", "tinyparse"]
77+
7578
def state(self) -> dict:
7679
return json.loads((self.work / "upstream" / "STATE.json").read_text())
7780

@@ -115,7 +118,7 @@ def walk_to_draft(self, channel=("--channel", "issue")):
115118
self.up("init", REPO, *channel, "--user", "@psjg")
116119
self.up("rules", "--local", "tinyparse")
117120
self.up("rules", "classify", "--outcome", "welcome", "--form", "a sentence saying an AI tool helped")
118-
self.up("search", "--keywords", "trailing empty field")
121+
self.up("search", "--keywords", "trailing empty field", *self.history())
119122
self.up("search", "mark", "12", "related", "closed; trailing whitespace, a different bug")
120123
self.up("search", "mark", "7", "unrelated", "documentation")
121124
self.up("claim", "add", "--text", CLAIM, "--cmd", CMD, "--permalink", self.link)
@@ -399,11 +402,33 @@ def test_unmarked_hit_blocks_evidence(self):
399402
self.up("init", REPO, "--channel", "issue", "--user", "@psjg")
400403
self.up("rules", "--local", "tinyparse")
401404
self.up("rules", "classify", "--outcome", "welcome", "--form", "x")
402-
self.up("search", "--keywords", "trailing")
405+
self.up("search", "--keywords", "trailing", *self.history())
403406
self.up("search", "mark", "12", "unrelated", "whitespace")
404407
self.assertIn("hit #7 is not marked", self.up("status"))
405408
self.up("claim", "add", "--text", "t", "--cmd", "true", "--no-permalink", "none", ok=False)
406409

410+
def test_history_search_required_and_fix_commits_become_hits(self):
411+
"""A fix merged after the version the user ran is found in the
412+
commits, not in an issue search: its PR number must be marked."""
413+
self.up("init", REPO, "--channel", "issue", "--user", "@psjg")
414+
self.up("rules", "--local", "tinyparse")
415+
self.up("rules", "classify", "--outcome", "welcome", "--form", "x")
416+
self.up("search", "--keywords", "trailing")
417+
self.up("search", "mark", "12", "unrelated", "whitespace")
418+
self.up("search", "mark", "7", "unrelated", "docs")
419+
self.assertIn("no search of the commits since the reported version", self.up("status"))
420+
self.up("search", "--history", "HEAD", "--clone", "tinyparse", ok=False) # not a range
421+
clone = self.work / "tinyparse"
422+
with open(clone / "tinyparse" / "__init__.py", "a") as f:
423+
f.write("# fixed\n")
424+
subprocess.run(["git", "-C", str(clone), "commit", "-qam", "fix: keep a trailing empty field (#31)"],
425+
env=self.env, check=True)
426+
out = self.up("search", "--history", f"{self.sha}..HEAD", "--clone", "tinyparse", "--paths", "tinyparse")
427+
self.assertIn("#31 [COMMITTED] ", out)
428+
self.assertIn("hit #31 is not marked", self.up("status"))
429+
self.up("search", "mark", "31", "duplicate", "fixed on main, unreleased")
430+
self.assertEqual(self.state()["state"], "duplicate")
431+
407432
def test_unpinned_permalink_refused(self):
408433
self.walk_to_draft()
409434
self.up("claim", "add", "--text", "t", "--cmd", "true", "--permalink",
@@ -417,7 +442,7 @@ def test_refuse_outcome_gathers_facts_then_stops(self):
417442
self.up("rules", "--local", "tinyparse")
418443
self.up("rules", "classify", "--outcome", "refuse", "--form", "a human writes the description")
419444
self.assertEqual(self.state()["state"], "search")
420-
self.up("search", "--keywords", "trailing empty field")
445+
self.up("search", "--keywords", "trailing empty field", *self.history())
421446
self.up("search", "mark", "12", "unrelated", "whitespace")
422447
self.up("search", "mark", "7", "unrelated", "docs")
423448
self.up("claim", "add", "--text", CLAIM, "--cmd", CMD, "--permalink", self.link)
@@ -439,7 +464,7 @@ def test_mailing_list_forbids_html(self):
439464
self.up("init", REPO, "--channel", "issue", "--list", "~psjg/[email protected]", "--user", "@psjg")
440465
self.up("rules", "--local", "tinyparse")
441466
self.up("rules", "classify", "--outcome", "welcome", "--form", "say so in the report")
442-
self.up("search", "--keywords", "trailing")
467+
self.up("search", "--keywords", "trailing", *self.history())
443468
self.assertIn("list archive", self.up("status"))
444469
self.up("search", "--archive-cmd", "echo no patches found")
445470
self.up("search", "mark", "12", "unrelated", "whitespace")
@@ -548,7 +573,7 @@ def setUp(self):
548573
def evidence(self, wd: str):
549574
self.up("--workdir", wd, "rules", "--local", "tinyparse")
550575
self.up("--workdir", wd, "rules", "classify", "--outcome", "welcome", "--form", "a sentence saying an AI tool helped")
551-
self.up("--workdir", wd, "search", "--keywords", "trailing empty field")
576+
self.up("--workdir", wd, "search", "--keywords", "trailing empty field", *self.history())
552577
self.up("--workdir", wd, "search", "mark", "12", "unrelated", "whitespace")
553578
self.up("--workdir", wd, "search", "mark", "7", "unrelated", "docs")
554579
self.up("--workdir", wd, "claim", "add", "--text", "The patched build passes 621/621.",
@@ -614,7 +639,7 @@ def test_duplicate_stops(self):
614639
self.up("init", REPO, "--channel", "issue", "--user", "@psjg")
615640
self.up("rules", "--local", "tinyparse")
616641
self.up("rules", "classify", "--outcome", "welcome", "--form", "x")
617-
out = self.up("search", "--keywords", "trailing empty field")
642+
out = self.up("search", "--keywords", "trailing empty field", *self.history())
618643
self.assertIn("#12 [CLOSED/NOT_PLANNED]", out)
619644
self.up("search", "mark", "12", "duplicate", "closed as not planned: by design since 0.3")
620645
self.assertEqual(self.state()["state"], "duplicate")
@@ -629,7 +654,7 @@ def test_handle_without_at(self):
629654
out = self.up("rules", "--local", "tinyparse")
630655
self.assertIn("thread:", out) # the maintainer's no-mentions request is among the hits
631656
self.up("rules", "classify", "--outcome", "welcome", "--form", "x", "--no-mentions")
632-
self.up("search", "--keywords", "sep")
657+
self.up("search", "--keywords", "sep", *self.history())
633658
self.up("search", "mark", "12", "unrelated", "whitespace")
634659
self.up("search", "mark", "7", "related", "this thread")
635660
self.up("claim", "add", "--text", CLAIM, "--cmd", CMD, "--permalink", self.link)

‎skills/upstream/scripts/upstream.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def g_search(L, h):
225225
return (need("issues" in kinds, "no successful issue search: `search --keywords \"...\"`")
226226
+ need("prs" in kinds, "no successful PR search for a fix already proposed: `search --keywords \"...\"`")
227227
+ need(not L.get("list") or "archive" in kinds, "no search of the list archive for proposed patches: `search --archive-cmd \"...\"`")
228+
+ need(L["channel"] == "comment" or "history" in kinds,
229+
"no search of the commits since the reported version: `search --history TAG..origin/DEFAULT --clone DIR [--paths ...]`")
228230
+ [f"hit #{n} is not marked: `search mark {n} duplicate|related|unrelated \"why\"`" for n in unmarked])
229231

230232

@@ -717,22 +719,37 @@ def cmd_search(a, w: Work):
717719
runs.append((kind, ["gh", sub, "list", "-R", L["repo"], "--state", "all", "--search", a.keywords, "--json", fields]))
718720
if a.archive_cmd:
719721
runs.append(("archive", a.archive_cmd))
722+
if a.history:
723+
if not a.clone or ".." not in a.history:
724+
raise Refused("--history takes REPORTED..DEFAULT (e.g. v0.1.9..origin/main) and needs --clone DIR")
725+
runs.append(("history", ["git", "-C", a.clone, "log", "--format=%h %s", a.history, "--", *(a.paths or [])]))
720726
if not runs:
721-
raise Refused("give --keywords \"...\" (issues and PRs) and, for a list, --archive-cmd \"...\"")
727+
raise Refused("give --keywords \"...\" (issues and PRs), --history REPORTED..DEFAULT --clone DIR, and, for a list, --archive-cmd \"...\"")
722728
for kind, argv in runs:
723729
if kind == "archive":
724730
rc, out = shell(argv, os.getcwd())
725731
line, err = argv, ""
732+
elif kind == "history":
733+
p = subprocess.run(argv, capture_output=True, text=True)
734+
rc, out, err, line = p.returncode, p.stdout, p.stderr, shlex.join(argv)
726735
else:
727736
rc, out, err = gh(*argv[1:])
728737
line = shlex.join(argv)
729738
L["searches"].append({"kind": kind, "cmd": line, "exit": rc, "at": now()})
730739
raw.append({"kind": kind, "cmd": line, "exit": rc, "stdout": out, "stderr": err})
731740
w.log(L, f"search {kind}: {line} -> exit {rc}")
732-
if kind != "archive" and rc == 0 and out.strip():
741+
if kind == "history" and rc == 0:
742+
# A fix merged after the reported version names its PR or issue in
743+
# the subject; each such number becomes a hit that must be marked.
744+
for commit in out.splitlines():
745+
for n in re.findall(r"#(\d+)", commit):
746+
L["hits"].setdefault(n, {"number": int(n), "title": commit, "state": "COMMITTED", "kind": kind})
747+
elif kind != "archive" and rc == 0 and out.strip():
733748
for h in json.loads(out):
734749
L["hits"][str(h["number"])] = {**h, "kind": kind}
735750
print(f"$ {line}\n exit {rc}" + (f": {err.strip()[:200]}" if rc else ""))
751+
if kind == "history" and rc == 0:
752+
print("\n".join(" " + c for c in out.splitlines()) or " (no commits in range)")
736753
(w.dir / "related.json").write_text(json.dumps(raw, indent=1) + "\n")
737754
for n, h in sorted(L["hits"].items(), key=lambda x: int(x[0])):
738755
mark = L["marks"].get(n, {}).get("mark", "UNMARKED")
@@ -1118,6 +1135,9 @@ def main(argv=None):
11181135
p.add_argument("why", nargs="?")
11191136
p.add_argument("--keywords")
11201137
p.add_argument("--archive-cmd", help="a command that searches the list archive for proposed patches")
1138+
p.add_argument("--history", help="REPORTED..DEFAULT: commits after the version the user ran (a fix may be merged, unreleased)")
1139+
p.add_argument("--clone", help="a local clone of the project, fetched")
1140+
p.add_argument("--paths", nargs="*", help="limit --history to the suspect files")
11211141
p = sub.add_parser("claim")
11221142
p.add_argument("action", choices=["add", "list", "rm"])
11231143
p.add_argument("n", nargs="?", type=int, help="for rm: the claim id")

0 commit comments

Comments
 (0)