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

opened this

Merged 12d 16h ago, 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.

Notes

opened this

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: --file needs FORGE_URL and FORGE_TOKEN; FORGE_REPO defaults to trevato/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 without src/hunt/file.ts.
  • Docs: docs/HUNT.md no 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_plan and estimate tools 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

Closes #15259

commented

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: --file needs FORGE_URL and FORGE_TOKEN; FORGE_REPO defaults to trevato/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 without src/hunt/file.ts.
  • Docs: docs/HUNT.md no 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_plan and estimate tools 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

commented

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, Location headers, link text), so a page could plant a fake <!-- hunt-key --> marker in it. A new quiet() now turns <!-- into &lt;!-- and --> into --&gt; in the evidence before it goes into the issue body (issueBody) or a comment (changedBody). Separately, keyIn now 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 in Filed.failed with its error and the run carries on, so filedLine still 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: Filed now records the cap the run actually used, and filedLine prints that instead of the FILE_CAP constant. 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, keyIn returns 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 1 and cap 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

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs