universal-dev-standards 5.0.0-beta.6 → 5.0.0-beta.7

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.
@@ -0,0 +1,568 @@
1
+ # Developer Persistent Memory Standards
2
+
3
+ > **Language**: English | [繁體中文](../locales/zh-TW/core/developer-memory.md)
4
+
5
+ **Version**: 1.0.0
6
+ **Last Updated**: 2026-02-07
7
+ **Applicability**: All software projects using AI assistants
8
+ **Scope**: universal
9
+ **Industry Standards**: None (UDS original)
10
+
11
+ ---
12
+
13
+ ## Purpose
14
+
15
+ This standard defines a structured system for capturing, retrieving, and surfacing developer experience insights (pitfalls, patterns, anti-patterns, mental models, etc.) across conversations and projects. It enables AI assistants to proactively leverage accumulated knowledge, reducing repeated mistakes and accelerating problem-solving.
16
+
17
+ ---
18
+
19
+ ## Quick Reference
20
+
21
+ ### Memory Entry Schema (Required Fields)
22
+
23
+ | Field | Type | Description |
24
+ |-------|------|-------------|
25
+ | `id` | string | Unique identifier (format: `MEM-YYYY-NNNN`) |
26
+ | `insight` | string | Core insight in one sentence |
27
+ | `category` | enum | One of 9 category types (see §2) |
28
+ | `confidence` | float | 0.0–1.0, dynamically adjusted via feedback |
29
+ | `created_at` | date | ISO 8601 date (YYYY-MM-DD) |
30
+
31
+ ### Memory Entry Schema (Optional Fields)
32
+
33
+ | Field | Type | Description |
34
+ |-------|------|-------------|
35
+ | `context` | string | Situation or environment where this applies |
36
+ | `anti_pattern` | string | What NOT to do (the mistake) |
37
+ | `resolution` | string | How to fix or avoid the issue |
38
+ | `example` | object | `{bad: string, good: string}` — code or approach examples |
39
+ | `tags` | list | Free-form tags for search (e.g., `["async", "race-condition"]`) |
40
+ | `applicability` | object | Language/framework scope (see §6) |
41
+ | `triggers` | list | Patterns that should cause this memory to surface |
42
+ | `related` | list | IDs of related memory entries |
43
+ | `validity` | object | Lifecycle metadata (see §7) |
44
+
45
+ ### Statistics Fields (Auto-managed)
46
+
47
+ | Field | Type | Description |
48
+ |-------|------|-------------|
49
+ | `stats.times_surfaced` | int | How many times this memory was shown |
50
+ | `stats.times_useful` | int | Positive feedback count |
51
+ | `stats.times_not_useful` | int | Negative feedback count |
52
+ | `stats.last_surfaced` | date | Last time this memory was pushed |
53
+
54
+ ### Feedback Log
55
+
56
+ | Field | Type | Description |
57
+ |-------|------|-------------|
58
+ | `feedback[]` | list | Array of feedback entries |
59
+ | `feedback[].date` | date | When feedback was given |
60
+ | `feedback[].result` | enum | `valid` / `invalid` / `needs-revision` |
61
+ | `feedback[].note` | string | Optional developer comment |
62
+
63
+ ---
64
+
65
+ ## 1. Memory Schema
66
+
67
+ ### 1.1 Full Schema Definition
68
+
69
+ ```yaml
70
+ # Memory Entry - Full Schema
71
+ id: "MEM-2026-0001" # Required: Unique ID
72
+ insight: "..." # Required: One-sentence core insight
73
+ category: pitfall # Required: One of 9 types
74
+ confidence: 0.85 # Required: 0.0–1.0
75
+ created_at: "2026-02-07" # Required: ISO date
76
+
77
+ # Optional fields
78
+ context: "When using async iterators in Node.js streams..."
79
+ anti_pattern: "Calling next() without awaiting the previous result"
80
+ resolution: "Always await each next() call or use for-await-of"
81
+ example:
82
+ bad: "iterator.next(); iterator.next();"
83
+ good: "for await (const chunk of iterator) { ... }"
84
+ tags: ["async", "streams", "node"]
85
+ applicability:
86
+ languages: ["javascript", "typescript"]
87
+ frameworks: []
88
+ universal: false
89
+ exclusions: []
90
+ triggers:
91
+ - "async iterator"
92
+ - "stream processing"
93
+ - "next() called multiple times"
94
+ related: ["MEM-2026-0005"]
95
+ validity:
96
+ type: versioned # evergreen | versioned | temporal
97
+ version_bound: "node >= 18"
98
+ expires_at: null
99
+
100
+ # Auto-managed
101
+ stats:
102
+ times_surfaced: 12
103
+ times_useful: 9
104
+ times_not_useful: 1
105
+ last_surfaced: "2026-02-01"
106
+ feedback:
107
+ - date: "2026-01-15"
108
+ result: valid
109
+ note: "Saved me 30 minutes debugging"
110
+ ```
111
+
112
+ ### 1.2 ID Format
113
+
114
+ | Component | Format | Example |
115
+ |-----------|--------|---------|
116
+ | Prefix | `MEM` | `MEM` |
117
+ | Year | `YYYY` | `2026` |
118
+ | Sequence | `NNNN` | `0001` |
119
+ | Full | `MEM-YYYY-NNNN` | `MEM-2026-0001` |
120
+
121
+ IDs are globally unique. Sequence resets yearly.
122
+
123
+ ---
124
+
125
+ ## 2. Memory Categories
126
+
127
+ | Category | Description | Example |
128
+ |----------|-------------|---------|
129
+ | `pitfall` | Common mistake or trap | "Off-by-one error in pagination with 0-based API" |
130
+ | `pattern` | Proven solution or best practice | "Use builder pattern for complex object construction" |
131
+ | `anti-pattern` | Known bad practice to avoid | "God object that handles all business logic" |
132
+ | `mental-model` | Conceptual framework for understanding | "Think of React state as a snapshot, not a variable" |
133
+ | `workaround` | Temporary fix for a known issue | "Add `--legacy-peer-deps` for npm 7+ peer conflicts" |
134
+ | `performance` | Performance insight or optimization | "Use `Map` instead of `Object` for frequent lookups" |
135
+ | `debugging-strategy` | Approach for diagnosing issues | "Binary search through git history with `git bisect`" |
136
+ | `tool-usage` | Tool/library tips and tricks | "Use `npx tsc --noEmit` for type-checking without build" |
137
+ | `decision-rationale` | Why a specific decision was made | "Chose PostgreSQL over MongoDB for transaction support" |
138
+
139
+ ---
140
+
141
+ ## 3. Four Operations
142
+
143
+ ### 3.1 Record (記錄)
144
+
145
+ #### Input Process
146
+
147
+ 1. Developer describes an insight in natural language
148
+ 2. AI structures it into the memory schema
149
+ 3. Developer confirms or edits the structured entry
150
+ 4. Entry is saved to the memory store
151
+
152
+ #### 30-Second Rule
153
+
154
+ Every memory entry must answer three questions:
155
+
156
+ | Question | Maps To |
157
+ |----------|---------|
158
+ | What is the specific problem? | `insight` |
159
+ | Why does it happen? | `context` + `anti_pattern` |
160
+ | How to fix/avoid it? | `resolution` |
161
+
162
+ #### Recording Levels
163
+
164
+ | Level | Fields | When to Use |
165
+ |-------|--------|-------------|
166
+ | Level 1: Quick | `insight`, `category`, `tags` | Quick note, will refine later |
167
+ | Level 2: Contextual | Level 1 + `context`, `anti_pattern`, `resolution` | Standard recording |
168
+ | Level 3: Refined | Level 2 + `example`, `triggers`, `applicability` | Important, frequently-used insight |
169
+
170
+ #### De-identification
171
+
172
+ Before storing, remove project-specific details:
173
+
174
+ | Remove | Keep |
175
+ |--------|------|
176
+ | API keys, secrets | Technical pattern |
177
+ | Project names, internal URLs | Framework/library names |
178
+ | Team member names | Language/version information |
179
+ | Proprietary business logic | Generic business logic pattern |
180
+
181
+ ### 3.2 Query (查詢)
182
+
183
+ #### Search Methods
184
+
185
+ | Method | Description | Example |
186
+ |--------|-------------|---------|
187
+ | Keyword | Free-text search across `insight`, `context`, `tags` | `"async race condition"` |
188
+ | Tag | Exact match on `tags` field | `tags: ["react", "hooks"]` |
189
+ | Category | Filter by category type | `category: pitfall` |
190
+ | Language | Filter by `applicability.languages` | `languages: ["python"]` |
191
+ | Confidence | Filter by confidence threshold | `confidence >= 0.7` |
192
+ | Combined | Multiple filters combined | `category: pitfall AND tags: ["react"]` |
193
+
194
+ #### Query Result Sorting
195
+
196
+ | Priority | Criteria |
197
+ |----------|----------|
198
+ | 1 | Relevance to current context |
199
+ | 2 | Confidence score (highest first) |
200
+ | 3 | Hit rate (`times_useful / times_surfaced`) |
201
+ | 4 | Recency (`created_at` newest first) |
202
+
203
+ ### 3.3 Feedback (回饋)
204
+
205
+ #### Feedback Actions
206
+
207
+ | Action | Effect on `confidence` | Effect on `stats` |
208
+ |--------|------------------------|-------------------|
209
+ | `valid` | +0.05 (cap at 1.0) | `times_useful += 1` |
210
+ | `invalid` | -0.15 (floor at 0.0) | `times_not_useful += 1` |
211
+ | `needs-revision` | -0.05 (floor at 0.0) | No change |
212
+
213
+ #### Confidence Adjustment Rules
214
+
215
+ | Condition | Action |
216
+ |-----------|--------|
217
+ | 3 consecutive `valid` | Bonus +0.05 |
218
+ | 3 consecutive `invalid` | Flag for review |
219
+ | `confidence < 0.2` | Flag for retirement |
220
+ | `confidence > 0.9` after 10+ uses | Mark as "proven" |
221
+
222
+ ### 3.4 Review (審查)
223
+
224
+ AI scans the memory store and generates a review report covering:
225
+
226
+ #### Merge Suggestions
227
+
228
+ | Trigger | Action |
229
+ |---------|--------|
230
+ | Two entries with >80% semantic similarity | Suggest merge |
231
+ | Same `tags` + same `category` + similar `insight` | Suggest merge |
232
+ | Merged entries inherit highest `confidence` | Preserve both feedback logs |
233
+
234
+ #### Retirement Suggestions
235
+
236
+ | Trigger | Action |
237
+ |---------|--------|
238
+ | `confidence < 0.2` | Suggest retirement |
239
+ | Not surfaced in 180+ days AND `confidence < 0.5` | Suggest retirement |
240
+ | 5+ `invalid` feedback entries | Suggest retirement |
241
+
242
+ #### Staleness Detection
243
+
244
+ | Trigger | Action |
245
+ |---------|--------|
246
+ | `validity.type == "versioned"` AND version is outdated | Flag as stale |
247
+ | `validity.type == "temporal"` AND `expires_at` passed | Flag as expired |
248
+ | `validity.type == "evergreen"` | Skip version check |
249
+
250
+ #### Revision Suggestions
251
+
252
+ | Trigger | Action |
253
+ |---------|--------|
254
+ | 2+ `needs-revision` feedback | Suggest revision |
255
+ | High `times_surfaced` but low `times_useful` ratio | Suggest revision |
256
+
257
+ ---
258
+
259
+ ## 4. Proactive Behavior Protocol
260
+
261
+ ### 4.1 Memory Surfacing (主動浮現)
262
+
263
+ #### When to Surface
264
+
265
+ | Timing | Behavior |
266
+ |--------|----------|
267
+ | Conversation start | Scan memory store, show top 3 relevant to stated task |
268
+ | During development | Detect code patterns, error messages, or tech decisions that match `triggers` |
269
+ | Before committing | Surface relevant pitfalls for changed files/patterns |
270
+
271
+ #### Surfacing Rules
272
+
273
+ | Rule | Value | Rationale |
274
+ |------|-------|-----------|
275
+ | Relevance threshold | > 0.7 | Avoid noise from loosely-related memories |
276
+ | Cooldown period | 7 days per entry | Prevent repetitive suggestions |
277
+ | Max per trigger | 3–5 entries | Information overload prevention |
278
+ | Overflow handling | AI summarizes into grouped insight | When > 5 matches found |
279
+
280
+ #### Surfacing Format
281
+
282
+ ```
283
+ 💡 Memory Match [MEM-2026-0042] (confidence: 0.85)
284
+ Category: pitfall | Tags: async, promise
285
+ Insight: Promise.all rejects on first failure — use Promise.allSettled for partial results
286
+ Context: When processing batch API calls where partial success is acceptable
287
+ ```
288
+
289
+ ### 4.2 Memory Extraction (主動萃取)
290
+
291
+ #### Trigger Signals
292
+
293
+ AI should detect these developer signals and suggest recording:
294
+
295
+ | Signal | Example |
296
+ |--------|---------|
297
+ | Repeated modification | Same code block edited 3+ times |
298
+ | Revert | `git revert` or manual undo |
299
+ | Insight language | "Oh!", "I see", "原來", "終於", "the trick is..." |
300
+ | Long debugging session | 10+ minutes on same error |
301
+ | Solution after struggle | Error → multiple attempts → resolution |
302
+
303
+ #### Extraction Flow
304
+
305
+ ```
306
+ 1. AI detects signal
307
+ 2. AI proposes: "It seems you discovered something. Want to record this insight?"
308
+ 3. AI pre-structures the entry based on conversation context
309
+ 4. Developer confirms / edits / skips
310
+ 5. If confirmed → saved to memory store
311
+ ```
312
+
313
+ ### 4.3 Memory Aggregation (主動聚合)
314
+
315
+ #### Aggregation Triggers
316
+
317
+ | Trigger | Action |
318
+ |---------|--------|
319
+ | 3+ related `pitfall` entries | Suggest grouping into a `mental-model` |
320
+ | 5+ entries with same tag | Suggest creating a topic summary |
321
+ | Scattered fragments about same concept | Suggest consolidation |
322
+
323
+ #### Upgrade Path
324
+
325
+ ```
326
+ Multiple pitfalls → Pattern → Mental Model
327
+ (fragments) (solution) (understanding)
328
+ ```
329
+
330
+ ---
331
+
332
+ ## 5. Noise Control
333
+
334
+ ### Push Levels
335
+
336
+ | Level | Name | Behavior |
337
+ |-------|------|----------|
338
+ | 0 | Silent | Never push; only respond to queries |
339
+ | 1 | Summary | Show count: "3 relevant memories found. Want to see them?" |
340
+ | 2 | Active (default) | Show top 3 with one-line summaries |
341
+ | 3 | Detailed | Show full entries with context and examples |
342
+
343
+ ### Noise Reduction Rules
344
+
345
+ | Rule | Description |
346
+ |------|-------------|
347
+ | Feedback-driven | If user marks 3+ surfaced memories as `invalid`, reduce to Level 1 |
348
+ | Session respect | After user says "not now", switch to Level 0 for current session |
349
+ | Confidence filter | Only surface entries with `confidence >= 0.5` |
350
+ | Proven bias | Prioritize entries with "proven" status (confidence > 0.9, 10+ uses) |
351
+
352
+ ---
353
+
354
+ ## 6. Cross-Language Applicability
355
+
356
+ ### Applicability Schema
357
+
358
+ ```yaml
359
+ applicability:
360
+ languages: ["javascript", "typescript"] # Applicable languages (empty = universal)
361
+ frameworks: ["react", "next.js"] # Applicable frameworks (empty = any)
362
+ universal: false # true = applies to all languages
363
+ exclusions: ["rust"] # Languages where this explicitly does NOT apply
364
+ ```
365
+
366
+ ### Applicability Rules
367
+
368
+ | Scenario | `universal` | `languages` | `exclusions` |
369
+ |----------|-------------|-------------|--------------|
370
+ | Applies to all languages | `true` | `[]` | `[]` |
371
+ | Language-specific | `false` | `["python", "ruby"]` | `[]` |
372
+ | All except some | `true` | `[]` | `["c", "assembly"]` |
373
+ | Framework-specific | `false` | `["javascript"]` | `[]` |
374
+
375
+ ---
376
+
377
+ ## 7. Knowledge Lifecycle
378
+
379
+ ### Validity Types
380
+
381
+ | Type | Description | Staleness Check |
382
+ |------|-------------|-----------------|
383
+ | `evergreen` | Always applicable (e.g., algorithm insight) | None |
384
+ | `versioned` | Tied to specific version (e.g., API behavior) | Check `version_bound` |
385
+ | `temporal` | Time-limited (e.g., workaround for a bug) | Check `expires_at` |
386
+
387
+ ### Validity Schema
388
+
389
+ ```yaml
390
+ validity:
391
+ type: versioned # evergreen | versioned | temporal
392
+ version_bound: "react >= 18" # For versioned type
393
+ expires_at: "2026-12-31" # For temporal type
394
+ ```
395
+
396
+ ### Confidence Lifecycle
397
+
398
+ ```
399
+ New entry: confidence = 0.5 (default)
400
+ ↓ valid feedback
401
+ Growing: 0.5 → 0.7 → 0.85
402
+ ↓ consistent positive use
403
+ Proven: 0.9+ (after 10+ surfacings)
404
+ ↓ invalid feedback / staleness
405
+ Declining: 0.85 → 0.6 → 0.3
406
+ ↓ retirement threshold
407
+ Retired: confidence < 0.2
408
+ ```
409
+
410
+ ### Retirement Conditions
411
+
412
+ An entry is flagged for retirement when ANY of:
413
+
414
+ - `confidence < 0.2`
415
+ - Not surfaced in 180+ days AND `confidence < 0.5`
416
+ - 5+ `invalid` feedback entries
417
+ - `validity.type == "temporal"` AND `expires_at` has passed
418
+ - `validity.type == "versioned"` AND version is no longer in use
419
+
420
+ Retired entries are archived (not deleted) for historical reference.
421
+
422
+ ---
423
+
424
+ ## 8. Metrics
425
+
426
+ ### Key Metrics
427
+
428
+ | Metric | Formula | Healthy Range |
429
+ |--------|---------|---------------|
430
+ | Hit rate | `times_useful / times_surfaced` | > 0.6 |
431
+ | Feedback ratio | `(valid + invalid) / times_surfaced` | > 0.3 |
432
+ | Library growth | New entries per month | 5–20 |
433
+ | Retirement rate | Retired entries per month | < 20% of new |
434
+ | Coverage | Categories with 5+ entries | 6+ of 9 categories |
435
+
436
+ ### Health Indicators
437
+
438
+ | Indicator | Good | Warning | Action Needed |
439
+ |-----------|------|---------|---------------|
440
+ | Avg confidence | > 0.6 | 0.4–0.6 | < 0.4 |
441
+ | Hit rate | > 0.6 | 0.3–0.6 | < 0.3 |
442
+ | Stale entries | < 10% | 10–25% | > 25% |
443
+ | Orphan entries (never surfaced) | < 15% | 15–30% | > 30% |
444
+
445
+ ---
446
+
447
+ ## 9. Storage Format
448
+
449
+ ### Recommended: YAML per Category
450
+
451
+ ```
452
+ .memory/
453
+ ├── pitfall.yaml
454
+ ├── pattern.yaml
455
+ ├── anti-pattern.yaml
456
+ ├── mental-model.yaml
457
+ ├── workaround.yaml
458
+ ├── performance.yaml
459
+ ├── debugging-strategy.yaml
460
+ ├── tool-usage.yaml
461
+ ├── decision-rationale.yaml
462
+ └── _index.yaml # ID registry and cross-references
463
+ ```
464
+
465
+ #### File Size Guideline
466
+
467
+ | Entries per File | Recommendation |
468
+ |------------------|----------------|
469
+ | < 100 | Single YAML file per category |
470
+ | 100–500 | Split by sub-topic within category |
471
+ | > 500 | Consider JSONL format |
472
+
473
+ ### Alternative: JSONL
474
+
475
+ For large memory stores, use one JSONL file per category:
476
+
477
+ ```
478
+ .memory/
479
+ ├── pitfall.jsonl
480
+ ├── pattern.jsonl
481
+ └── ...
482
+ ```
483
+
484
+ Each line is a complete JSON object representing one memory entry.
485
+
486
+ ### Index File (`_index.yaml`)
487
+
488
+ ```yaml
489
+ # Memory Index
490
+ last_id: "MEM-2026-0042"
491
+ total_entries: 42
492
+ by_category:
493
+ pitfall: 12
494
+ pattern: 8
495
+ anti-pattern: 5
496
+ mental-model: 3
497
+ workaround: 4
498
+ performance: 3
499
+ debugging-strategy: 2
500
+ tool-usage: 3
501
+ decision-rationale: 2
502
+ ```
503
+
504
+ ---
505
+
506
+ ## Related Standards
507
+
508
+ - [Anti-Hallucination Standards](anti-hallucination.md) — Evidence-based analysis applies to memory sourcing
509
+ - [AI Instruction Standards](ai-instruction-standards.md) — Token-efficient format for memory system instructions
510
+ - [AI-Friendly Architecture](ai-friendly-architecture.md) — Project structure enabling memory integration
511
+ - [Documentation Writing Standards](documentation-writing-standards.md) — Writing quality for memory entries
512
+
513
+ ---
514
+
515
+ ## 10. Architecture Decision: Always-On Protocol
516
+
517
+ ### Classification
518
+
519
+ Developer Persistent Memory is classified as an **Always-On Protocol**, not a User-Triggered workflow.
520
+
521
+ | Pattern | Characteristics | Examples | Skill Required? |
522
+ |---------|----------------|----------|-----------------|
523
+ | **User-Triggered** | User explicitly invokes, multi-step guided workflow | `/commit`, `/review`, `/spec` | Yes |
524
+ | **Always-On Protocol** | AI continuously follows rules after loading ai.yaml | Anti-hallucination, Developer Memory | No |
525
+
526
+ ### Rationale: No CLI / Skill / Slash Command Needed
527
+
528
+ | Component | Decision | Rationale |
529
+ |-----------|----------|-----------|
530
+ | CLI commands (`uds memory ...`) | **Not needed** | Core operations (semantic matching, insight extraction, confidence adjustment) require LLM intelligence; CLI can only do string matching |
531
+ | Skill (`skills/developer-memory/`) | **Not needed** | `developer-memory.ai.yaml` is self-sufficient with complete schema + rules + proactive protocol |
532
+ | `/memory add`, `/memory search` | **Not needed** | Contradicts the "proactive behavior" design — AI should extract and surface automatically |
533
+ | `/memory review` | **Deferred** | Only potentially useful command; defer until user feedback indicates need |
534
+
535
+ ### How It Works Without Additional Tooling
536
+
537
+ ```
538
+ AI loads developer-memory.ai.yaml
539
+
540
+ Rules automatically activate:
541
+ - proactive-surfacing: Surface relevant memories on context match
542
+ - proactive-extraction: Detect insight moments, offer to record
543
+ - proactive-aggregation: Suggest merging related entries
544
+ - noise-control: Respect push levels and cooldown
545
+
546
+ No explicit user trigger needed
547
+ ```
548
+
549
+ ### Future Considerations
550
+
551
+ If user feedback reveals:
552
+ - **Discoverability gap**: Consider a lightweight Skill (configuration detection + discoverability)
553
+ - **Explicit review need**: Consider `/memory review` slash command
554
+ - **Never needed**: `uds memory add/search` CLI commands — these operations inherently require LLM
555
+
556
+ ---
557
+
558
+ ## Version History
559
+
560
+ | Version | Date | Changes |
561
+ |---------|------|---------|
562
+ | 1.0.0 | 2026-02-07 | Initial standard: schema, 4 operations, proactive protocol, noise control, architecture decision (Always-On Protocol) |
563
+
564
+ ---
565
+
566
+ ## License
567
+
568
+ This standard is released under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).