From 9e8bfd6a5054ec70e5fe307e82a77bd6f9b0ddbe Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 17:16:24 +0000 Subject: [PATCH 1/4] feat: accept multiple search terms --- .changeset/search-terms.md | 8 ++++++ packages/client/src/commands/gh.ts | 20 +++++++++++++-- packages/core/src/actions.ts | 39 +++++++++++++++++++----------- test/unit/actions.test.ts | 9 +++++++ 4 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 .changeset/search-terms.md diff --git a/.changeset/search-terms.md b/.changeset/search-terms.md new file mode 100644 index 00000000..6cb76c07 --- /dev/null +++ b/.changeset/search-terms.md @@ -0,0 +1,8 @@ +--- +'gcb-core': minor +'gcb-client': minor +--- + +Search actions accept multiple positional terms (or one quoted phrase): the final positional is +repeatable, and each term is passed to `gh` as its own argument after `--`. Repository-scope +qualifier rejection applies to every term. diff --git a/packages/client/src/commands/gh.ts b/packages/client/src/commands/gh.ts index d3d2ea79..fc867339 100644 --- a/packages/client/src/commands/gh.ts +++ b/packages/client/src/commands/gh.ts @@ -13,7 +13,12 @@ import { remoteRepo } from './remotes.ts'; const ACTION_LINES = Object.values(GH_ACTIONS) .map((action) => { const positionals = action.positionals - .map((positional) => (positional.required === true ? `<${positional.name}>` : `[${positional.name}]`)) + .map((positional) => { + const repeat = positional.repeatable === true ? '...' : ''; + return positional.required === true + ? `<${positional.name}${repeat}>` + : `[${positional.name}${repeat}]`; + }) .join(' '); const flags = action.flags .map((flag) => { @@ -300,7 +305,18 @@ export async function runGh( const values: Record = {}; const bodyFile = args.value('body-file') !== undefined; + let repeatable = false; for (const [index, positional] of action.positionals.entries()) { + if (positional.repeatable === true) { + const rest = args.positionals.slice(index); + if (rest.length === 0) { + if (positional.required === true) fail(`gcb gh ${domain} ${command} needs ${positional.name}`); + } else { + values[positional.name] = rest; + } + repeatable = true; + break; + } const value = args.positionals[index]; if (value === undefined) { if (positional.required === true) fail(`gcb gh ${domain} ${command} needs ${positional.name}`); @@ -308,7 +324,7 @@ export async function runGh( } values[positional.name] = value; } - if (args.positionals.length > action.positionals.length) { + if (!repeatable && args.positionals.length > action.positionals.length) { fail(`gcb gh ${domain} ${command} has too many positional arguments`); } for (const flag of action.flags) { diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index f442c40d..85e55c59 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -28,6 +28,8 @@ export interface PositionalSpec { readonly name: string; readonly type: 'number' | 'string'; readonly required?: boolean; + /** The final positional collects all remaining arguments as a list. */ + readonly repeatable?: boolean; } /** A long flag an action accepts. */ @@ -761,7 +763,7 @@ const LABEL_DELETE: GhAction = { const SEARCH_ISSUES: GhAction = { name: 'search:issues', command: ['search', 'issues'], - positionals: [{ name: 'query', type: 'string' }], + positionals: [{ name: 'query', type: 'string', repeatable: true }], flags: [ { name: 'assignee', type: 'string' }, { name: 'author', type: 'string' }, @@ -785,7 +787,7 @@ const SEARCH_ISSUES: GhAction = { const SEARCH_PRS: GhAction = { name: 'search:prs', command: ['search', 'prs'], - positionals: [{ name: 'query', type: 'string' }], + positionals: [{ name: 'query', type: 'string', repeatable: true }], flags: [ { name: 'assignee', type: 'string' }, { name: 'author', type: 'string' }, @@ -956,10 +958,16 @@ export function buildGhArgv( if (positional.required === true) throw new ActionError(`${name} needs ${positional.name}`); continue; } - if (positional.type === 'number') { - argv.push(String(asNumber(value, positional.name))); - } else { - trailingPositionals.push(asString(value, positional.name)); + const items = positional.repeatable && Array.isArray(value) ? value : [value]; + if (positional.repeatable !== true && Array.isArray(value)) { + throw new ActionError(`positional ${positional.name} is not repeatable`); + } + for (const item of items) { + if (positional.type === 'number') { + argv.push(String(asNumber(item, positional.name))); + } else { + trailingPositionals.push(asString(item, positional.name)); + } } } } @@ -1053,14 +1061,17 @@ export function buildGhArgv( } } - if ( - action.command[0] === 'search' && - typeof values['query'] === 'string' && - /(?:^|[\s(])-?(?:repo|org|user):/iu.test(values['query']) - ) { - throw new ActionError( - 'search query cannot contain repo:, org: or user:; the broker scopes it to --repo', - ); + if (action.command[0] === 'search') { + const terms = Array.isArray(values['query']) ? values['query'] : [values['query']]; + if ( + terms.some( + (term) => typeof term === 'string' && /(?:^|[\s(])-?(?:repo|org|user):/iu.test(term), + ) + ) { + throw new ActionError( + 'search query cannot contain repo:, org: or user:; the broker scopes it to --repo', + ); + } } if (typeof values['title'] === 'string') { if (values['title'].trim() === '') { diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 2ba9b119..7bf80e4a 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -295,6 +295,15 @@ describe('buildGhArgv', () => { } assert.doesNotThrow(() => buildGhArgv('search:issues', { query: 'is:issue label:bug' }, 'acme/widget')); + assert.deepEqual( + buildGhArgv('search:issues', { query: ['is:issue', 'label:bug'] }, 'acme/widget'), + ['search', 'issues', '--repo', 'acme/widget', '--', 'is:issue', 'label:bug'], + ); + assert.deepEqual( + buildGhArgv('search:issues', { query: ['"authentication bug"'] }, 'acme/widget'), + ['search', 'issues', '--repo', 'acme/widget', '--', '"authentication bug"'], + ); + assert.deepEqual( buildGhArgv('search:prs', { query: 'fix', draft: true }, 'acme/widget'), ['search', 'prs', '--draft', '--repo', 'acme/widget', '--', 'fix'], From 82b673a793e6213840f8394d879f5732801ab70a Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 17:31:19 +0000 Subject: [PATCH 2/4] test: cover qualifiers in later search terms --- packages/client/src/commands/gh.ts | 6 +++--- test/unit/actions.test.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/client/src/commands/gh.ts b/packages/client/src/commands/gh.ts index fc867339..42783ad6 100644 --- a/packages/client/src/commands/gh.ts +++ b/packages/client/src/commands/gh.ts @@ -308,11 +308,11 @@ export async function runGh( let repeatable = false; for (const [index, positional] of action.positionals.entries()) { if (positional.repeatable === true) { - const rest = args.positionals.slice(index); - if (rest.length === 0) { + const remaining = args.positionals.slice(index); + if (remaining.length === 0) { if (positional.required === true) fail(`gcb gh ${domain} ${command} needs ${positional.name}`); } else { - values[positional.name] = rest; + values[positional.name] = remaining; } repeatable = true; break; diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 7bf80e4a..77c616e7 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -277,6 +277,16 @@ describe('buildGhArgv', () => { 'bug', ], ); + for (const query of [ + ['bug', 'repo:other/repo'], + ['is:issue', '(org:other)'], + ['ok', '-user:x'], + ]) { + assert.throws( + () => buildGhArgv('search:issues', { query }, 'acme/widget'), + /cannot contain repo:, org: or user:/u, + ); + } for (const query of [ 'repo:other/repo bug', 'org:other bug', From a434830a2f1321135559db3b322abd8ef714e974 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 17:45:30 +0000 Subject: [PATCH 3/4] test: pass the phrase as the shell would --- test/unit/actions.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 77c616e7..cf70d896 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -310,8 +310,8 @@ describe('buildGhArgv', () => { ['search', 'issues', '--repo', 'acme/widget', '--', 'is:issue', 'label:bug'], ); assert.deepEqual( - buildGhArgv('search:issues', { query: ['"authentication bug"'] }, 'acme/widget'), - ['search', 'issues', '--repo', 'acme/widget', '--', '"authentication bug"'], + buildGhArgv('search:issues', { query: ['authentication bug'] }, 'acme/widget'), + ['search', 'issues', '--repo', 'acme/widget', '--', 'authentication bug'], ); assert.deepEqual( From 08d23cd13320dd1b3e33bb374e4c8c692e01929b Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 18:16:18 +0000 Subject: [PATCH 4/4] test: cover search terms through the client path --- test/unit/gh-command.test.ts | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/unit/gh-command.test.ts b/test/unit/gh-command.test.ts index 18a8e807..251ed25b 100644 --- a/test/unit/gh-command.test.ts +++ b/test/unit/gh-command.test.ts @@ -497,6 +497,47 @@ describe('gcb gh', () => { } }); + it('preserves multiple search terms and quoted phrases through the client', async () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gcb-gh-search-')); + const socketPath = path.join(root, 'broker.sock'); + const block: StaticHostConfig = { provider: 'static', allow: ['acme/widget'] }; + const config: BrokerConfig = { + socketPath, + socketMode: 0o600, + auditPath: null, + tokenCacheSkewSeconds: 300, + hosts: { 'github.com': block }, + }; + const audit: AuditSink = { path: null, record: () => {}, close: () => Promise.resolve() }; + const seen: unknown[] = []; + const provider: Provider = { + name: 'static', + getCredential: async () => ({ username: 'u', password: 'p', expiresAt: Date.now() + 1000 }), + runAction: async (request) => { + seen.push(request.values['query']); + return { stdout: '', stderr: '', code: 0, signal: null, truncated: false, timedOut: false }; + }, + }; + const broker = await startBroker({ config, audit, providers: new Map([['github.com', provider]]) }); + try { + const terms = await runGhCli( + ['search', 'issues', 'is:issue', 'label:bug', '--repo', 'acme/widget', '--socket', socketPath], + root, + ); + assert.equal(terms.status, 0, terms.stderr); + assert.deepEqual(seen[0], ['is:issue', 'label:bug']); + const phrase = await runGhCli( + ['search', 'issues', 'authentication bug', '--repo', 'acme/widget', '--socket', socketPath], + root, + ); + assert.equal(phrase.status, 0, phrase.stderr); + assert.deepEqual(seen[1], ['authentication bug']); + } finally { + await broker.close(); + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('reports truncation and timed-out writes', async () => { const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gcb-gh-output-')); const socketPath = path.join(root, 'broker.sock');