@techdivision/opencode-time-tracking 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/hooks/EventHook.ts +5 -2
- package/src/services/TicketResolver.ts +37 -8
- package/src/utils/AgentMatcher.ts +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.7.1] - 2025-03-01
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Fix `agent_defaults` lookup to be tolerant of `@` prefix in agent names
|
|
10
|
+
- Add `AgentMatcher` utility for consistent agent name normalization across the codebase
|
|
11
|
+
|
|
5
12
|
## [0.7.0] - 2025-02-04
|
|
6
13
|
|
|
7
14
|
### Added
|
package/package.json
CHANGED
package/src/hooks/EventHook.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { MessageWithParts } from "../types/MessageWithParts"
|
|
|
12
12
|
import type { OpencodeClient } from "../types/OpencodeClient"
|
|
13
13
|
import type { TimeTrackingConfig } from "../types/TimeTrackingConfig"
|
|
14
14
|
|
|
15
|
+
import { AgentMatcher } from "../utils/AgentMatcher"
|
|
15
16
|
import { DescriptionGenerator } from "../utils/DescriptionGenerator"
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -193,9 +194,11 @@ export function createEventHook(
|
|
|
193
194
|
const agentString = session.agent?.name ?? null
|
|
194
195
|
|
|
195
196
|
// Check if agent should be ignored (tolerant matching: with or without @ prefix)
|
|
196
|
-
const normalizedAgent = agentString
|
|
197
|
+
const normalizedAgent = agentString
|
|
198
|
+
? AgentMatcher.normalize(agentString)
|
|
199
|
+
: null
|
|
197
200
|
const isIgnoredAgent = config.ignored_agents?.some(
|
|
198
|
-
(ignored) =>
|
|
201
|
+
(ignored) => AgentMatcher.normalize(ignored) === normalizedAgent
|
|
199
202
|
)
|
|
200
203
|
|
|
201
204
|
if (agentString && isIgnoredAgent) {
|
|
@@ -6,6 +6,8 @@ import type { ResolvedTicketInfo } from "../types/ResolvedTicketInfo"
|
|
|
6
6
|
import type { TimeTrackingConfig } from "../types/TimeTrackingConfig"
|
|
7
7
|
import type { TicketExtractor } from "./TicketExtractor"
|
|
8
8
|
|
|
9
|
+
import { AgentMatcher } from "../utils/AgentMatcher"
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* Resolves tickets and account keys using fallback hierarchy.
|
|
11
13
|
*
|
|
@@ -65,11 +67,13 @@ export class TicketResolver {
|
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
// 2. Try agent default
|
|
69
|
-
|
|
70
|
+
// 2. Try agent default (tolerant matching: with or without @ prefix)
|
|
71
|
+
const agentKey = agentName ? this.findAgentKey(agentName) : null
|
|
72
|
+
|
|
73
|
+
if (agentKey) {
|
|
70
74
|
return {
|
|
71
|
-
ticket: this.config.agent_defaults[
|
|
72
|
-
accountKey: this.resolveAccountKey(
|
|
75
|
+
ticket: this.config.agent_defaults![agentKey].issue_key,
|
|
76
|
+
accountKey: this.resolveAccountKey(agentKey),
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -88,16 +92,41 @@ export class TicketResolver {
|
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
|
|
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
|
+
|
|
91
120
|
/**
|
|
92
121
|
* Resolves account key using fallback hierarchy.
|
|
93
122
|
*
|
|
94
|
-
* @param
|
|
123
|
+
* @param agentKey - The agent config key, or `null`
|
|
95
124
|
* @returns Resolved Tempo account key
|
|
96
125
|
*/
|
|
97
|
-
private resolveAccountKey(
|
|
126
|
+
private resolveAccountKey(agentKey: string | null): string {
|
|
98
127
|
// 1. Agent-specific account_key
|
|
99
|
-
if (
|
|
100
|
-
return this.config.agent_defaults[
|
|
128
|
+
if (agentKey && this.config.agent_defaults?.[agentKey]?.account_key) {
|
|
129
|
+
return this.config.agent_defaults[agentKey].account_key!
|
|
101
130
|
}
|
|
102
131
|
|
|
103
132
|
// 2. Global default account_key (required)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utility for normalizing agent names.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes agent names to a canonical form.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Agent names can appear with or without the "@" prefix
|
|
10
|
+
* depending on the source (SDK, config, user input).
|
|
11
|
+
* This class ensures consistent comparison by normalizing
|
|
12
|
+
* all agent names to the "@<name>" format.
|
|
13
|
+
*/
|
|
14
|
+
export class AgentMatcher {
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes an agent name to canonical form (with @ prefix).
|
|
17
|
+
*
|
|
18
|
+
* @param agentName - The agent name to normalize
|
|
19
|
+
* @returns The normalized agent name with @ prefix
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* AgentMatcher.normalize("developer") // → "@developer"
|
|
24
|
+
* AgentMatcher.normalize("@developer") // → "@developer"
|
|
25
|
+
* AgentMatcher.normalize("@time-tracking") // → "@time-tracking"
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
static normalize(agentName: string): string {
|
|
29
|
+
return agentName.startsWith("@") ? agentName : `@${agentName}`
|
|
30
|
+
}
|
|
31
|
+
}
|