@@ -6,6 +6,8 @@ import type { ResolvedTicketInfo } from "../types/ResolvedTicketInfo"
66import type { TimeTrackingConfig } from "../types/TimeTrackingConfig"
77import type { TicketExtractor } from "./TicketExtractor"
88
9+ import { AgentMatcher } from "../utils/AgentMatcher"
10+
911/**
1012 * Resolves tickets and account keys using fallback hierarchy.
1113 *
@@ -65,11 +67,13 @@ export class TicketResolver {
6567 }
6668 }
6769
68- // 2. Try agent default
69- if ( agentName && this . config . agent_defaults ?. [ agentName ] ) {
70+ // 2. Try agent default (tolerant matching: with or without @ prefix)
71+ const agentKey = agentName ? this . findAgentKey ( agentName ) : null
72+
73+ if ( agentKey ) {
7074 return {
71- ticket : this . config . agent_defaults [ agentName ] . issue_key ,
72- accountKey : this . resolveAccountKey ( agentName ) ,
75+ ticket : this . config . agent_defaults ! [ agentKey ] . issue_key ,
76+ accountKey : this . resolveAccountKey ( agentKey ) ,
7377 }
7478 }
7579
@@ -88,16 +92,41 @@ export class TicketResolver {
8892 }
8993 }
9094
95+ /**
96+ * Finds the matching config key for an agent name.
97+ *
98+ * @param agentName - The agent name from the SDK
99+ * @returns The matching config key, or `null` if not found
100+ *
101+ * @remarks
102+ * Normalizes both the agent name and config keys to ensure
103+ * matching works regardless of @ prefix.
104+ */
105+ private findAgentKey ( agentName : string ) : string | null {
106+ const defaults = this . config . agent_defaults
107+
108+ if ( ! defaults ) {
109+ return null
110+ }
111+
112+ const normalized = AgentMatcher . normalize ( agentName )
113+ const key = Object . keys ( defaults ) . find (
114+ ( k ) => AgentMatcher . normalize ( k ) === normalized
115+ )
116+
117+ return key ?? null
118+ }
119+
91120 /**
92121 * Resolves account key using fallback hierarchy.
93122 *
94- * @param agentName - The agent name , or `null`
123+ * @param agentKey - The agent config key , or `null`
95124 * @returns Resolved Tempo account key
96125 */
97- private resolveAccountKey ( agentName : string | null ) : string {
126+ private resolveAccountKey ( agentKey : string | null ) : string {
98127 // 1. Agent-specific account_key
99- if ( agentName && this . config . agent_defaults ?. [ agentName ] ?. account_key ) {
100- return this . config . agent_defaults [ agentName ] . account_key !
128+ if ( agentKey && this . config . agent_defaults ?. [ agentKey ] ?. account_key ) {
129+ return this . config . agent_defaults [ agentKey ] . account_key !
101130 }
102131
103132 // 2. Global default account_key (required)
0 commit comments