applyUpdate applies one key/value update; callers must hold the write lock.
(key, value string)
| 129 | |
| 130 | // applyUpdate applies one key/value update; callers must hold the write lock. |
| 131 | func (ps *UserProfileStore) applyUpdate(key, value string) updateResult { |
| 132 | if field, op, ok := resolveListKey(key); ok { |
| 133 | return updateResult{field: field, changed: ps.applyListOp(field, op, value), affirmable: op == opUpsert} |
| 134 | } |
| 135 | lk := strings.ToLower(strings.TrimSpace(key)) |
| 136 | switch lk { |
| 137 | case "sensitive_mark", "mark_sensitive": |
| 138 | return updateResult{changed: ps.setSensitive(value, true)} |
| 139 | case "sensitive_unmark", "unmark_sensitive": |
| 140 | return updateResult{changed: ps.setSensitive(value, false)} |
| 141 | } |
| 142 | if value == "" { |
| 143 | return updateResult{} |
| 144 | } |
| 145 | switch lk { |
| 146 | case "name": |
| 147 | return updateResult{field: "name", changed: ps.setScalar(&ps.profile.Name, value), affirmable: true} |
| 148 | case "role": |
| 149 | return updateResult{field: "role", changed: ps.setScalar(&ps.profile.Role, value), affirmable: true} |
| 150 | case "expertise_level", "expertise", "level": |
| 151 | return updateResult{field: "expertise_level", changed: ps.setScalar(&ps.profile.ExpertiseLevel, normalizeExpertise(value)), affirmable: true} |
| 152 | case "preferred_language", "language", "lang": |
| 153 | return updateResult{field: "preferred_language", changed: ps.setScalar(&ps.profile.PreferredLang, value), affirmable: true} |
| 154 | case "communication_style", "comm_style", "style": |
| 155 | return updateResult{field: "communication_style", changed: ps.setScalar(&ps.profile.CommStyle, value), affirmable: true} |
| 156 | case "company", "employer", "organization", "org": |
| 157 | return updateResult{field: "company", changed: ps.setScalar(&ps.profile.Company, value), affirmable: true} |
| 158 | case "location", "city", "country", "timezone", "tz": |
| 159 | return updateResult{field: "location", changed: ps.setScalar(&ps.profile.Location, value), affirmable: true} |
| 160 | case "milestone", "milestones": |
| 161 | return updateResult{field: "milestones", changed: ps.addMilestones(value)} |
| 162 | case "stance", "stances", "position", "opinion": |
| 163 | return updateResult{field: "stances", changed: ps.upsertStances(value), affirmable: true} |
| 164 | case "environment_remove", "env_remove": |
| 165 | return updateResult{field: "environment", changed: ps.removeEnvironment(value)} |
| 166 | case "preferences_remove", "preference_remove", "remove_preference", "remove_preferences": |
| 167 | return updateResult{field: "preferences", changed: ps.removePreferences(value)} |
| 168 | } |
| 169 | if envKey, ok := strings.CutPrefix(lk, "env_"); ok && envKey != "" { |
| 170 | return updateResult{field: "environment", changed: ps.setEnvironment(envKey, value), affirmable: true} |
| 171 | } |
| 172 | // Store as generic preference. This is the escape hatch that keeps the |
| 173 | // profile open-ended: any personal fact the model reports with a novel |
| 174 | // key is preserved instead of dropped. Meta is tracked per key so |
| 175 | // sensitivity and staleness work at preference granularity. |
| 176 | if ps.profile.Preferences == nil { |
| 177 | ps.profile.Preferences = make(map[string]string) |
| 178 | } |
| 179 | if ps.profile.Preferences[key] != value { |
| 180 | ps.profile.Preferences[key] = value |
| 181 | return updateResult{field: "pref:" + key, changed: true, affirmable: true} |
| 182 | } |
| 183 | return updateResult{field: "pref:" + key, changed: false, affirmable: true} |
| 184 | } |
| 185 | |
| 186 | // touchFieldMeta maintains provenance/freshness/sensitivity for one applied |
| 187 | // update; callers must hold the write lock. Returns whether meta changed. |
no test coverage detected