Public: anyone can read this; the crew can change it.

`forge search <words>` finds code, issues and pulls across the repositories you can read, as /api/v1/search does #7463

opened this

Merged 32d 5h ago, live in production

Adds forge search , which searches code, issues, pulls and repositories through GET /api/v1/search. tsc and the three CLI test files (cli-search, cli-asks, cli-pins-pages) pass; I didn't run the whole suite. src/cli/api.ts: a new ForgeApi.search(q, { kind, limit }) method.

Notes

opened this

Adds forge search <words…>, which searches code, issues, pulls and repositories through GET /api/v1/search. tsc and the three CLI test files (cli-search, cli-asks, cli-pins-pages) pass; I didn't run the whole suite.

  • src/cli/api.ts: a new ForgeApi.search(q, { kind, limit }) method. It returns the forge's answer as it came, so --json can print it unchanged. ApiError gets an optional retryAfter, read from the retry-after header on any failed response.
  • src/cli/main.ts:
    • The words are joined into q. --kind code|issues|pulls|repos|all and --limit N are checked before any request; when they're left out, the forge's defaults apply.
    • Code hits print as owner/name:path:line text, with the indentation trimmed and the text cut to the terminal width.
    • Issues and pulls print as owner/name#N title state, with the columns lined up. Repositories print as owner/name description.
    • Each group is headed kind (count) and says "more not shown" when the API cut the list short. A note follows the code group when the time limit for code search ran out.
    • Every field passes through inert(), so control characters from the API can't reach the terminal.
    • No hits prints Nothing found for "words". and exits 0. Empty words print usage and exit 2. A 429 prints the API's message with (retry in Ns), unless the message already names that time, and exits with the new EXIT.rateLimited (5).
    • The command is listed in forge help.
  • README.md: two example lines under "On your machine".

What to look at: the API has no pulls kind (searchKind in src/core/search.ts treats anything unknown as all), and its issues kind returns issues and pulls together. So --kind pulls sends kind=issues and prints only the pulls; --kind issues likewise prints only the issues. I left the server alone.

test/cli-search.test.ts runs the CLI as a separate process against a fake /api/v1/search. It checks:

  • the request's q/kind/limit, including the pulls → issues mapping
  • the exact printed lines for code, issues, pulls and repos, all within 79 columns
  • one kind on its own, and --json round-tripping
  • the empty case, and both forms of the 429
  • usage errors sending no request, and forge help listing the command
  • control characters being made harmless

To try it: forge search retry budget, or forge search retry --kind code --limit 20.

🤖 Generated with Claude Code

Closes #7378

Show 4 earlier items

7 earlier comments
commented

The full suite on this head squashed onto main (accaa65) was red, so the pull has not joined the merge queue.

It named no test (a type error, a timeout, a setup step).

The gate's log: /api/v1/repos/trevato/forge/gates/1793498642199-694862a76e95/log

It is proved again on a push.

commented

forge search <words> looks up code, issues, pulls and repositories the token can read, using GET /api/v1/search, and prints one hit per line grouped by kind:

  • Code prints as owner/name:path:line text.
  • Issues and pulls print as owner/name#N title state.
  • Repositories print as owner/name description.

Options:

  • --kind code|issues|pulls|repos|all keeps one kind. Anything else exits 2.
  • --limit N caps how many hits come back.
  • --json prints the forge's answer as it came.

The API has no pulls kind of its own: its issues covers both issues and pulls. So --kind issues and --kind pulls ask for the API's maximum of 100, keep the one kind, then cut to --limit. Asking for N and filtering afterwards would print fewer than N. In --json, truncated.issues is set when more matched than were kept.

When the forge says "not now" (429), it prints the forge's message with the retry time and exits 6. That code is new because refused already took 5. A 401 exits 3, as being not signed in does elsewhere.

docs/CLI.md has a forge search section, and exit code 6 is in its table. main is merged in. Both sides had added to the same places, so the merge keeps both:

  • forge asks --ship/--close/--dismiss/--undo and forge search sit side by side.
  • --kind and --reason both take values.
  • The search and bulk/undo client methods both stay in src/cli/api.ts.

The last full-suite gate (on 694862a, squashed onto main at accaa65) failed before any test ran. mkdir -p .forge-cache ran, then tsc stopped with TS5033: Could not write file '.forge-cache/tsc.tsbuildinfo': mkdir .forge-cache: no such file or directory. That is the gate's environment, not this change, which touches nothing under .forge-cache or the build setup. This push re-runs it.

Sentinel's non-blocking README note is taken: the two near-identical --kind examples are now one. I left out a server-side pulls kind, which would close the remaining gap where more than 100 hits match. It changes /api/v1/search and belongs in its own issue.

bun x tsc --noEmit passes, and so do the CLI test files (test/cli-*.test.ts, test/hollow-cli.test.ts): 113 pass, 0 fail. The rest of the suite was not run here.

To try it: forge search retry budget, then forge search retry --kind pulls --limit 3 --json.

🤖 Generated with Claude Code

commented

The full suite on this head squashed onto main (accaa65) was red, so the pull has not joined the merge queue.

Red tests:

  • a real roll of two forge processes on one data directory > an old forge that lingers past a probe period refuses nobody
  • a push in flight on the old forge completes across the roll, and no connection is refused
  • model budget: zero, an own subscription, a capped grant > a capped grant runs, and stops being offered at the cap

The gate's log: /api/v1/repos/trevato/forge/gates/1793498776833-5509c652784e/log

It is proved again on a push.

commented

forge search <words> looks up code, issues, pulls and repositories the token can read, using GET /api/v1/search, and prints one hit per line grouped by kind:

  • Code prints as owner/name:path:line text.
  • Issues and pulls print as owner/name#N title state.
  • Repositories print as owner/name description.

Options:

  • --kind code|issues|pulls|repos|all keeps one kind. Anything else exits 2.
  • --limit N caps how many hits come back.
  • --json prints the forge's answer as it came.

The API has no pulls kind of its own: its issues covers both issues and pulls. So --kind issues and --kind pulls ask for the API's maximum of 100, keep the one kind, then cut to --limit. Asking for N and filtering afterwards would print fewer than N. In --json, truncated.issues is set when more matched than were kept.

When the forge says "not now" (429), it prints the forge's message with the retry time and exits 6. That code is new because refused already took 5. A 401 exits 3, as being not signed in does elsewhere. docs/CLI.md has a forge search section and exit 6 in its table, and the README has one example per form.

The last gate's three red tests are in code this pull doesn't touch. It changes only src/cli/api.ts, src/cli/main.ts, test/cli-search.test.ts, the README and docs/CLI.md. Each failure was the runner's environment, not an assertion about behaviour:

  • model-grant: the clone failed with Unable to read current working directory.
  • rehearsal: "the old forge did not come up".
  • release-handover: the push was declined by a pre-receive hook while the forge was being swapped mid-push.

The other shards on that run ended with exit 143, which means they were killed. Run here, test/rehearsal.test.ts, test/model-grant.test.ts and test/release-handover.test.ts pass: 20 pass, 0 fail. main has not moved since the last merge, so this push is an empty commit that re-runs the gate. No test was changed.

I left out a server-side pulls kind, which would close the remaining gap where more than 100 hits match and fewer than N are the kind asked for. It changes /api/v1/search and belongs in its own issue.

To try it: forge search retry budget, then forge search retry --kind pulls --limit 3 --json.

🤖 Generated with Claude Code

commented

The full suite on this head squashed onto main (accaa65) was red, so the pull has not joined the merge queue.

Red tests:

  • a real roll of two forge processes on one data directory > an old forge that lingers past a probe period refuses nobody
  • a push in flight on the old forge completes across the roll, and no connection is refused
  • model budget: zero, an own subscription, a capped grant > a capped grant runs, and stops being offered at the cap

The gate's log: /api/v1/repos/trevato/forge/gates/1793498990474-b5dbea925fec/log

It is proved again on a push.

commented

forge search <words> looks up code, issues, pulls and repositories the token can read, using GET /api/v1/search, and prints one hit per line grouped by kind:

  • Code prints as owner/name:path:line text.
  • Issues and pulls print as owner/name#N title state.
  • Repositories print as owner/name description.

Options:

  • --kind code|issues|pulls|repos|all keeps one kind. Anything else exits 2.
  • --limit N caps how many hits come back.
  • --json prints the forge's answer as it came.

The API has no pulls kind of its own: its issues covers both issues and pulls. So --kind issues and --kind pulls ask for the API's maximum of 100, keep the one kind, then cut to --limit. Asking for N and filtering afterwards would print fewer than N. In --json, truncated.issues is set when more matched than were kept.

When the forge says "not now" (429), it prints the forge's message with the retry time and exits 6. That code is new because refused already took 5. A 401 exits 3, as being not signed in does elsewhere. docs/CLI.md has a forge search section and exit 6 in its table. The change is limited to src/cli/api.ts, src/cli/main.ts, test/cli-search.test.ts, the README and docs/CLI.md.

The full gate on main at accaa65 is red for a reason outside this pull, and the same failure turned this head red twice:

  • The real failure: test/rehearsal.test.ts passes its first real roll (31 s), then its second roll throws "the old forge did not come up" 110 ms in.
  • The other three reds are fail-fast killing their shards. model-grant's clone loses its working directory and release-handover's push is declined mid-roll; neither is an assertion about behaviour.
  • Not this pull: #7588 and #7608, gated on the same main, show the same rehearsal reds. The server that rehearsal boots (src/main.ts) does not import src/cli/*; only the local TUI does.
  • Run here: the three red files pass (20 pass, 0 fail), but with the test socket on a loopback port. The gate binds a unix socket instead, which this sandbox can't do, so I couldn't reproduce its failure.

I opened #7632 to fix or quarantine the rehearsal test on main. This push is an empty commit that re-runs the gate; it stays red until #7632 lands or the test passes on a retry. No test was changed.

As juniper asked, I opened #7633 for a server-side pulls kind in /api/v1/search. It would close the remaining gap where more than 100 hits match and fewer than N are the kind asked for.

To try it: forge search retry budget, then forge search retry --kind pulls --limit 3 --json.

🤖 Generated with Claude Code

commented

The full suite on this head squashed onto main (accaa65) was red, so the pull has not joined the merge queue.

Red tests:

  • a real roll of two forge processes on one data directory > an old forge that lingers past a probe period refuses nobody
  • a push in flight on the old forge completes across the roll, and no connection is refused
  • model budget: zero, an own subscription, a capped grant > a capped grant runs, and stops being offered at the cap

The gate's log: /api/v1/repos/trevato/forge/gates/1793499139966-1f0f8323abdd/log

It is proved again on a push.

commented

Declined: the gate is red because of main, not this pull, and nothing on this branch can make it green. I pushed nothing this time. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m6ae23x2jjh7yn8myq49y9m0 Left open: someone has spoken on this pull.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs