Public: anyone can read this; the crew can change it.
A hunter finding files itself: one issue per key, a comment only when its evidence changes #15279
Check · Review · Land · Live done — Landed and live in production.
bun scripts/hunt.ts --file now files what the hunter finds as forge issues: one issue per finding key, and a comment on that issue only when the evidence has changed. The new tests pass and bun x tsc --noEmit is clean.
shipped production is serving it deploy 3fede26
1 earlier comment · 1 event
bun scripts/hunt.ts <origin> --file now files what the hunter finds as forge issues: one issue per finding key, and a comment on that issue only when the evidence has changed. The new tests pass and bun x tsc --noEmit is clean. I didn't run the full suite: scripts/fast.ts said the diff is too broad to name tests for (because scripts/hunt.ts changed), and no other test mentions the hunt script or docs/HUNT.md.
- How it finds its own issues (
src/hunt/file.ts): the forge's issue list has no text search. So the filer asks who the token belongs to (GET /api/v1/user), lists that account's issues in every state, and reads a hidden marker in each body:<!-- hunt-key: … -->plus<!-- hunt-evidence: <fingerprint> -->. Nothing is stored locally. Someone else's issue that happens to carry the marker is ignored. - When it comments: the fingerprint covers the repro text, the URL and the status, but not the time, bytes or milliseconds, which change on every run. A rerun with the same fingerprint writes nothing. A different one adds a comment with the new evidence and the new marker.
- Closed issues: these are never reopened. A new issue is opened that says "The same finding was filed before in #N, since closed."
- Flood cap: at most 5 writes per run, counting new issues and comments together. The rest are listed as held back, counted in a line on stderr, and filed on a later run.
- Running it:
--fileneedsFORGE_URLandFORGE_TOKEN;FORGE_REPOdefaults totrevato/forge. The JSON output and exit codes are unchanged. - Tests (
test/hunt-file.test.ts): these run against an in-memory stub forge. They file the same finding again with only the timing changed and get one issue and no writes, then change the status and get exactly one comment, then rerun and get nothing new. They also check that a closed issue is linked and not reopened, that a stranger's marker is ignored, and that 7 findings become 5 issues now and 2 on the next run. They fail withoutsrc/hunt/file.ts. - Docs:
docs/HUNT.mdno longer lists filing as not built, and describes how it works.
Left out:
- Filed issues get no labels. The labels for each kind of finding (bug, high, polish) are only added by the in-process filers. Doing it here would mean extra label-creation calls through the API.
- "Links" means naming the closed issue in the new issue's text, not a dependency link.
- There is no schedule yet; it is still one pass per run.
- I didn't keep the plan on the issue: the
keep_planandestimatetools weren't available in this run.
No page changed, so there are no review steps.
To try it: FORGE_URL=… FORGE_TOKEN=… bun scripts/hunt.ts https://lab--forge-trevato-apps.open-platform.sh --file twice. The second run should report opened 0 and comment only where evidence changed.
🤖 Generated with Claude Code
The filing logic matches the forge's real list routes (author/state/cursor on issues, after/next on comments), the tests cover the issue's three behaviours, and docs/HUNT.md is updated. One thing must change before this lands.
FIRST: the issue body embeds target-controlled text (paths, Location headers, link text) from evidenceOf(f) unescaped, before the <!-- hunt-key --> marker. KEY_RE takes the first match, so a page that serves a link or redirect containing <!-- hunt-key: other%3Akey --> can make the hunter's issue answer to a different key, which suppresses or misdirects later filing. Fix: neutralise <!-- and --> in the evidence before it goes into any body (for example replace <!-- with <!--), and read the key from the last marker, not the first. Add a test where a finding's evidence contains a fake marker and the real key still wins.
Also, smaller: (a) filedLine prints the constant FILE_CAP, not the cap actually used; (b) if one API call throws mid-run, the report of what was already written is lost. Catch per finding, record it as failed, and still print filedLine, so a rerun is not surprised. No page changed, so no review steps are needed.
scripts/hunt.ts --file now files hunt findings through the forge API: one issue per finding key, and a comment only when the evidence fingerprint changes. An issue closed for a key is never reopened; a new issue is opened that names the old one. A run makes at most 5 writes. Findings over that cap are counted as held back and filed on the next run.
This push fixes the issues from review, in src/hunt/file.ts:
- Key spoofing: evidence comes from the target (paths,
Locationheaders, link text), so a page could plant a fake<!-- hunt-key -->marker in it. A newquiet()now turns<!--into<!--and-->into-->in the evidence before it goes into the issue body (issueBody) or a comment (changedBody). Separately,keyInnow reads the last key marker in a body, the one the filer writes after the evidence, instead of the first. This also covers bodies written before evidence was escaped. - A failed API call: each finding is now filed in its own
try. If a call throws, that finding is recorded inFiled.failedwith its error and the run carries on, sofiledLinestill reports what was already written. Listing the hunter's existing issues still stops the run if it fails, since nothing has been written at that point. - The cap in the log:
Filednow records thecapthe run actually used, andfiledLineprints that instead of theFILE_CAPconstant. It also prints failures, with each key and its error.
Two tests were added in test/hunt-file.test.ts:
- A finding whose evidence carries a fake key marker and a fake evidence marker. The body shows the markers escaped,
keyInreturns the real key, and a rerun leaves the issue unchanged. - A forge stub that fails the second of three issue creations, with a cap of 2. The first is opened, the second is recorded as failed, the third is held back, and the log line reads
opened 1,failed 1andcap 2 a run.
bun scripts/gate.ts --fix and bun x tsc --noEmit pass. scripts/fast.ts said the diff was too broad to pick tests (exit 2), so I ran test/hunt-file.test.ts and test/hunt.test.ts: 20 pass. The gate prints two "one implementation?" notes about stubForge in the test file; they were already there before this change and do not fail it. No page changed, so there are no review steps.
To try it: bun test test/hunt-file.test.ts.
🤖 Generated with Claude Code
Clean. Evidence is neutralised by quiet() and the key is read from the last marker, with a spoof test. Only the hunter account's own issues are matched. Closed issues are never reopened and the new issue names the old one. Writes are capped at 5 a run, per-finding failures are reported, and the how-to is in docs/HUNT.md, not the README. No page changed, so there is nothing to see in the preview. Not blocking: the 50-page listing bound silently stops at 5000 issues, and evidence could carry an @mention into a comment.
bun scripts/hunt.ts <origin> --filenow files what the hunter finds as forge issues: one issue per finding key, and a comment on that issue only when the evidence has changed. The new tests pass andbun x tsc --noEmitis clean. I didn't run the full suite:scripts/fast.tssaid the diff is too broad to name tests for (becausescripts/hunt.tschanged), and no other test mentions the hunt script ordocs/HUNT.md.src/hunt/file.ts): the forge's issue list has no text search. So the filer asks who the token belongs to (GET /api/v1/user), lists that account's issues in every state, and reads a hidden marker in each body:<!-- hunt-key: … -->plus<!-- hunt-evidence: <fingerprint> -->. Nothing is stored locally. Someone else's issue that happens to carry the marker is ignored.--fileneedsFORGE_URLandFORGE_TOKEN;FORGE_REPOdefaults totrevato/forge. The JSON output and exit codes are unchanged.test/hunt-file.test.ts): these run against an in-memory stub forge. They file the same finding again with only the timing changed and get one issue and no writes, then change the status and get exactly one comment, then rerun and get nothing new. They also check that a closed issue is linked and not reopened, that a stranger's marker is ignored, and that 7 findings become 5 issues now and 2 on the next run. They fail withoutsrc/hunt/file.ts.docs/HUNT.mdno longer lists filing as not built, and describes how it works.Left out:
keep_planandestimatetools weren't available in this run.No page changed, so there are no
reviewsteps.To try it:
FORGE_URL=… FORGE_TOKEN=… bun scripts/hunt.ts https://lab--forge-trevato-apps.open-platform.sh --filetwice. The second run should report opened 0 and comment only where evidence changed.🤖 Generated with Claude Code
Closes #15259