@@ -124,13 +124,23 @@ func (p *tagProcessor) processTags(existingCategoryTagMap map[string]map[string]
124124 }
125125 for _ , tagName := range tagNames {
126126 if tag , ok := existingTaskTags [tagName ]; ! ok {
127- tagsToCreate = append (tagsToCreate , & database.Tag {
128- Name : tagName ,
129- Category : category ,
130- Scope : p .tagScope ,
131- BuiltIn : false , // new tag is absolutely not built-in
132- Group : "" , // keep empty
133- })
127+ // Before creating a new tag, search for an existing built-in tag with the
128+ // same name across all categories. This handles the case where a tag like
129+ // "jax" (framework) appears under the generic "tags" frontmatter key, which
130+ // gets mapped to the "task" category by formatCategoryName. Without this
131+ // lookup, the system would incorrectly create a new task-category tag
132+ // instead of reusing the existing built-in framework tag.
133+ if builtIn := findBuiltInTagByName (existingCategoryTagMap , tagName ); builtIn != nil {
134+ tagsMatched = append (tagsMatched , builtIn )
135+ } else {
136+ tagsToCreate = append (tagsToCreate , & database.Tag {
137+ Name : tagName ,
138+ Category : category ,
139+ Scope : p .tagScope ,
140+ BuiltIn : false , // new tag is absolutely not built-in
141+ Group : "" , // keep empty
142+ })
143+ }
134144 } else {
135145 tagsMatched = append (tagsMatched , tag )
136146 }
@@ -141,6 +151,17 @@ func (p *tagProcessor) processTags(existingCategoryTagMap map[string]map[string]
141151 return tagsMatched , tagsToCreate
142152}
143153
154+ // findBuiltInTagByName searches for a built-in tag with the given name across all categories.
155+ // Returns the first built-in tag found, or nil if none exists.
156+ func findBuiltInTagByName (existingCategoryTagMap map [string ]map [string ]* database.Tag , name string ) * database.Tag {
157+ for _ , tags := range existingCategoryTagMap {
158+ if tag , ok := tags [name ]; ok && tag .BuiltIn {
159+ return tag
160+ }
161+ }
162+ return nil
163+ }
164+
144165func (p * tagProcessor ) mapCategoryTag (tags []* database.Tag ) map [string ]map [string ]* database.Tag {
145166 predefinedCategoryTagMap := make (map [string ]map [string ]* database.Tag )
146167 for _ , tag := range tags {
0 commit comments