Repository navigation
feat: stamp the coding agent in the request origin #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
erikengervall
wants to merge
4
commits into
main
Choose a base branch
from
capy/stamp-the-coding-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
99cfc95
feat: stamp the coding agent in the request origin
erikengervall a81623d
fix: address review on agent origin (opt-out parsing, pinned test ori…
erikengervall e69d046
fix: carry the agent origin alongside the integration headers after r…
erikengervall 134243a
test: cover every Codex marker and isolate the origin cache test from…
erikengervall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import { handleInteractExecute } from '../../commands/interact'; | ||
| import { initializeConfig } from '../../utils/config'; | ||
| import { setupTest, teardownTest } from '../utils/mock-client'; | ||
|
|
||
| vi.mock('../../utils/agent-origin', () => ({ | ||
| getCliOrigin: () => 'cli.test@1.0.0', | ||
| })); | ||
|
|
||
| vi.mock('../../utils/output', () => ({ writeOutput: vi.fn() })); | ||
|
|
||
| describe('handleInteractExecute', () => { | ||
| let mockFetch: ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeEach(() => { | ||
| setupTest(); | ||
| initializeConfig({ | ||
| apiKey: 'test-api-key', | ||
| apiUrl: 'https://api.firecrawl.dev', | ||
| }); | ||
| mockFetch = vi.fn().mockResolvedValue({ | ||
| ok: true, | ||
| status: 200, | ||
| json: async () => ({ success: true, stdout: 'ok' }), | ||
| }); | ||
| vi.stubGlobal('fetch', mockFetch); | ||
| vi.spyOn(process.stderr, 'write').mockImplementation(() => true); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| vi.restoreAllMocks(); | ||
| teardownTest(); | ||
| }); | ||
|
|
||
| it('sends the CLI origin and integration in the request body', async () => { | ||
| await handleInteractExecute({ | ||
| scrapeId: 'scrape-1', | ||
| code: 'console.log(1)', | ||
| }); | ||
|
|
||
| expect(mockFetch).toHaveBeenCalledTimes(1); | ||
| const [url, init] = mockFetch.mock.calls[0] as [string, RequestInit]; | ||
| expect(url).toBe('https://api.firecrawl.dev/v2/scrape/scrape-1/interact'); | ||
| expect(JSON.parse(init.body as string)).toEqual({ | ||
| origin: 'cli.test@1.0.0', | ||
| integration: 'cli', | ||
| code: 'console.log(1)', | ||
| language: 'node', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { describe, it, expect, afterEach, vi } from 'vitest'; | ||
| import packageJson from '../../../package.json'; | ||
| import { buildCliOrigin, detectAgent } from '../../utils/agent-origin'; | ||
|
|
||
| const version = packageJson.version; | ||
|
|
||
| describe('detectAgent', () => { | ||
| it.each([ | ||
| [{ CLAUDECODE: '1' }, 'claude-code'], | ||
| [{ CLAUDE_CODE_ENTRYPOINT: 'cli' }, 'claude-code'], | ||
| [{ CODEX_SANDBOX: 'seatbelt' }, 'codex'], | ||
| [{ CODEX_SANDBOX_NETWORK_DISABLED: '1' }, 'codex'], | ||
| [{ CODEX_THREAD_ID: 'abc' }, 'codex'], | ||
| [{ CODEX_MANAGED_BY_NPM: '1' }, 'codex'], | ||
| [{ CODEX_MANAGED_BY_BUN: '1' }, 'codex'], | ||
| [{ CODEX_MANAGED_BY_PNPM: '1' }, 'codex'], | ||
| [{ CODEX_MANAGED_BY_VITE_PLUS: '1' }, 'codex'], | ||
| [{ CURSOR_AGENT: '1' }, 'cursor'], | ||
| [{ GEMINI_CLI: '1' }, 'gemini-cli'], | ||
| [{ OPENCODE: '1' }, 'opencode'], | ||
| [{ GOOSE_TERMINAL: '1' }, 'goose'], | ||
| [{ CLINE_ACTIVE: 'true' }, 'cline'], | ||
| ])('maps %j to %s', (env, slug) => { | ||
| expect(detectAgent(env)).toBe(slug); | ||
| }); | ||
|
|
||
| it('returns undefined without agent variables', () => { | ||
| expect(detectAgent({ PATH: '/usr/bin', TERM_PROGRAM: 'vscode' })).toBe( | ||
| undefined | ||
| ); | ||
| }); | ||
|
|
||
| it('ignores empty and falsy values', () => { | ||
| expect(detectAgent({ CLAUDECODE: '', GEMINI_CLI: '0' })).toBe(undefined); | ||
| expect(detectAgent({ OPENCODE: 'false' })).toBe(undefined); | ||
| }); | ||
|
|
||
| it('prefers the innermost agent when several are detected', () => { | ||
| expect(detectAgent({ CLAUDECODE: '1', OPENCODE: '1' })).toBe('opencode'); | ||
| }); | ||
|
|
||
| it.each(['1', 'true', 'YES', 'on'])( | ||
| 'returns undefined when the opt-out is %s', | ||
| (value) => { | ||
| expect( | ||
| detectAgent({ | ||
| CLAUDECODE: '1', | ||
| FIRECRAWL_CLI_DISABLE_AGENT_ORIGIN: value, | ||
| }) | ||
| ).toBe(undefined); | ||
| } | ||
| ); | ||
|
|
||
| it.each(['0', 'false', 'no', 'off', ''])( | ||
| 'keeps the agent when the opt-out is %j', | ||
| (value) => { | ||
| expect( | ||
| detectAgent({ | ||
| CLAUDECODE: '1', | ||
| FIRECRAWL_CLI_DISABLE_AGENT_ORIGIN: value, | ||
| }) | ||
| ).toBe('claude-code'); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| describe('buildCliOrigin', () => { | ||
| it('stamps the agent before the version', () => { | ||
| expect(buildCliOrigin({ CURSOR_AGENT: '1' })).toBe(`cli.cursor@${version}`); | ||
| }); | ||
|
|
||
| it('falls back to plain cli@<version>', () => { | ||
| expect(buildCliOrigin({})).toBe(`cli@${version}`); | ||
| expect( | ||
| buildCliOrigin({ | ||
| GEMINI_CLI: '1', | ||
| FIRECRAWL_CLI_DISABLE_AGENT_ORIGIN: '1', | ||
| }) | ||
| ).toBe(`cli@${version}`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getCliOrigin', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| vi.resetModules(); | ||
| }); | ||
|
|
||
| it('computes the origin once per process', async () => { | ||
| for (const name of [ | ||
| 'CLAUDECODE', | ||
| 'CLAUDE_CODE_ENTRYPOINT', | ||
| 'CODEX_SANDBOX', | ||
| 'CODEX_SANDBOX_NETWORK_DISABLED', | ||
| 'CODEX_THREAD_ID', | ||
| 'CODEX_MANAGED_BY_NPM', | ||
| 'CODEX_MANAGED_BY_BUN', | ||
| 'CODEX_MANAGED_BY_PNPM', | ||
| 'CODEX_MANAGED_BY_VITE_PLUS', | ||
| 'CURSOR_AGENT', | ||
| 'OPENCODE', | ||
| 'GOOSE_TERMINAL', | ||
| 'CLINE_ACTIVE', | ||
| 'FIRECRAWL_CLI_DISABLE_AGENT_ORIGIN', | ||
| ]) | ||
| vi.stubEnv(name, ''); | ||
| vi.stubEnv('GEMINI_CLI', '1'); | ||
|
capy-ai[bot] marked this conversation as resolved.
|
||
| vi.resetModules(); | ||
| const { getCliOrigin } = await import('../../utils/agent-origin'); | ||
| expect(getCliOrigin()).toBe(`cli.gemini-cli@${version}`); | ||
|
|
||
| vi.stubEnv('GEMINI_CLI', ''); | ||
| vi.stubEnv('OPENCODE', '1'); | ||
| expect(getCliOrigin()).toBe(`cli.gemini-cli@${version}`); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.