@@ -69,10 +69,8 @@ export type AgentRuntime =
6969
7070interface VendorRule {
7171 name : Exclude < AgentRuntime , null > ;
72- /** Check returns true when the named agent is driving the CLI. */
72+ /** Check returns true when the named agent (or, in WORKSPACE_RULES, that editor or host) runs the CLI. */
7373 check : ( env : NodeJS . ProcessEnv ) => boolean ;
74- /** Narrower than `check` when `check` also matches a person in that editor's terminal or host. */
75- agentOnly ?: ( env : NodeJS . ProcessEnv ) => boolean ;
7674}
7775
7876// Ordering matters: the FIRST rule that matches wins. Put more specific rules
@@ -313,11 +311,15 @@ const VENDOR_RULES: VendorRule[] = [
313311 name : "claude_agent_sdk" ,
314312 check : ( env ) => typeof env [ "CLAUDE_AGENT_SDK_VERSION" ] === "string" ,
315313 } ,
316- // Editor terminals and hosted workspaces: these mark where the shell runs,
317- // not that an agent drives it, so every agent marker above wins over them.
314+ ] ;
315+
316+ // Editor terminals and hosted workspaces mark where a shell runs, not that an
317+ // agent drives it. Checked after every agent marker, the AI_AGENT name check
318+ // included, and never counted by isAgentDriven().
319+ const WORKSPACE_RULES : VendorRule [ ] = [
318320 // Cursor's TERM_PROGRAM identifies the IDE terminal only.
319321 // Source: https://docs.cursor.com/en/agent/terminal
320- { name : "cursor" , check : ( env ) => env [ "TERM_PROGRAM" ] === "cursor" , agentOnly : ( ) => false } ,
322+ { name : "cursor" , check : ( env ) => env [ "TERM_PROGRAM" ] === "cursor" } ,
321323 // Windsurf (Codeium) integrated terminal — exports TERM_PROGRAM=windsurf.
322324 // Attested across many independent detectors (nx
323325 // packages/nx/src/native/ide/detection.rs, adonisjs/application, ag-grid
@@ -329,15 +331,13 @@ const VENDOR_RULES: VendorRule[] = [
329331 {
330332 name : "windsurf" ,
331333 check : ( env ) => env [ "TERM_PROGRAM" ] ?. toLowerCase ( ) === "windsurf" ,
332- agentOnly : ( ) => false ,
333334 } ,
334335 // Replit — REPL_ID and REPLIT_USER are long-documented environment
335336 // variables exposed inside every Replit workspace.
336337 // Source: https://docs.replit.com/replit-workspace/configuring-the-environment
337338 {
338339 name : "replit" ,
339340 check : ( env ) => typeof env [ "REPL_ID" ] === "string" || typeof env [ "REPLIT_USER" ] === "string" ,
340- agentOnly : ( ) => false ,
341341 } ,
342342] ;
343343
@@ -449,16 +449,17 @@ export function detectAgentRuntime(): AgentRuntime {
449449 for ( const rule of VENDOR_RULES ) {
450450 if ( rule . check ( process . env ) ) return rule . name ;
451451 }
452- return aiAgentFallback ( process . env ) ;
452+ return (
453+ aiAgentFallback ( process . env ) ??
454+ WORKSPACE_RULES . find ( ( rule ) => rule . check ( process . env ) ) ?. name ??
455+ null
456+ ) ;
453457}
454458
455459/** An agent is running this shell, not a person typing in an editor's terminal or a hosted workspace. */
456460export function isAgentDriven ( env : NodeJS . ProcessEnv = process . env ) : boolean {
457461 if ( isGeminiManagedAgent ( ) ) return true ;
458- return (
459- VENDOR_RULES . some ( ( rule ) => ( rule . agentOnly ?? rule . check ) ( env ) ) ||
460- aiAgentFallback ( env ) !== null
461- ) ;
462+ return VENDOR_RULES . some ( ( rule ) => rule . check ( env ) ) || aiAgentFallback ( env ) !== null ;
462463}
463464
464465/** Observed harness marker, not proof of a vendor, benchmark, or human user. */
0 commit comments