@dzhechkov/keysarium 1.2.0 → 1.4.0
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/README.md +29 -11
- package/package.json +2 -2
- package/src/utils.js +1 -1
- package/templates/.claude/commands/brain-export.md +99 -20
- package/templates/.claude/commands/brain-import.md +75 -4
- package/templates/.claude/commands/bto-benchmark.md +302 -0
- package/templates/.claude/commands/harvest.md +28 -46
- package/templates/.claude/rules/trust-tiers.md +1 -0
- package/templates/.claude/skills/knowledge-extractor/SKILL.md +254 -0
- package/templates/.claude/skills/knowledge-extractor/modules/01-extract.md +188 -0
- package/templates/.claude/skills/knowledge-extractor/modules/02-classify.md +99 -0
- package/templates/.claude/skills/knowledge-extractor/modules/03-gate.md +150 -0
- package/templates/.claude/skills/knowledge-extractor/modules/04-integrate.md +159 -0
- package/templates/.claude/skills/knowledge-extractor/references/artifact-categories.md +100 -0
- package/templates/.claude/skills/knowledge-extractor/references/maturity-model.md +94 -0
- package/templates/.claude/skills/knowledge-extractor/references/quality-gates.md +98 -0
- package/templates/.claude/skills/knowledge-extractor/templates/artifact-card.md +63 -0
- package/templates/.claude/skills/knowledge-extractor/templates/harvest-report.md +102 -0
- package/templates/CLAUDE.md +42 -22
- package/templates/docs/continuous-learning-guide.md +622 -0
- package/templates/docs/feature-adr/01-architecture.md +750 -0
- package/templates/docs/feature-adr/02-functionality.md +712 -0
- package/templates/docs/feature-adr/03-deployment-guide.md +614 -0
- package/templates/docs/feature-adr/04-admin-guide.md +564 -0
- package/templates/docs/feature-adr/05-user-guide.md +508 -0
- package/templates/docs/feature-adr/06-user-flows.md +1101 -0
- package/templates/docs/improvement-directions.md +8 -4
- package/templates/docs/keysarium-core/01-architecture.md +559 -0
- package/templates/docs/keysarium-core/02-functionality.md +955 -0
- package/templates/docs/keysarium-core/03-deployment-guide.md +625 -0
- package/templates/docs/keysarium-core/04-admin-guide.md +529 -0
- package/templates/docs/keysarium-core/05-user-guide.md +599 -0
- package/templates/docs/keysarium-core/06-user-flows.md +804 -0
- package/templates/docs/skills-bto/01-deployment-guide.md +1 -1
- package/templates/docs/skills-bto/02-admin-guide.md +4 -1
- package/templates/docs/skills-bto/03-user-guide.md +4 -3
- package/templates/docs/skills-bto/04-infrastructure-requirements.md +2 -1
- package/templates/docs/skills-bto/05-architecture.md +11 -11
- package/templates/docs/skills-bto/06-user-flows.md +2 -1
- package/templates/lib/dream-engine.md +1 -1
- package/templates/lib/memory-protocol.md +131 -22
- package/templates/lib/reward-tracker.md +6 -3
|
@@ -98,7 +98,7 @@ echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
|
|
|
98
98
|
source ~/.bashrc
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
> **Токены и стоимость:** Полный BTO-цикл (BUILD + TEST + OPTIMIZE) потребляет примерно 100–200K токенов.
|
|
101
|
+
> **Токены и стоимость:** Полный BTO-цикл (BUILD + BENCHMARK + TEST + OPTIMIZE) потребляет примерно 100–200K токенов. BENCHMARK (B0-B3) добавляет ~3.5K токенов (B0/B1/B3 детерминистические, B2 consistency probe — 3× haiku). Детальная разбивка: BUILD ~22K, BENCHMARK ~3.5K, TEST Layer 2 ~19K (sonnet×3), OPTIMIZE 3 rounds ~131K. Итого ~175K токенов за полный прогон. Отдельный `/bto-benchmark` потребляет ~3.5K токенов, `/bto-test` с Layer 2 — около 15–20K токенов.
|
|
102
102
|
|
|
103
103
|
### 1.4. Git (опционально, но рекомендуется)
|
|
104
104
|
|
|
@@ -27,16 +27,19 @@
|
|
|
27
27
|
| Компонент | Путь | Назначение |
|
|
28
28
|
|-----------|------|------------|
|
|
29
29
|
| BTO Skill | `.claude/skills/bto/` | Основной оркестратор: загружается командами |
|
|
30
|
-
| SKILL.md | `.claude/skills/bto/SKILL.md` | Точка входа, документирует все
|
|
30
|
+
| SKILL.md | `.claude/skills/bto/SKILL.md` | Точка входа, документирует все четыре модуля |
|
|
31
31
|
| Модуль BUILD | `.claude/skills/bto/modules/build.md` | Протокол генерации артефактов |
|
|
32
|
+
| Модуль BENCHMARK | `.claude/skills/bto/modules/benchmark.md` | Детерминистический бенчмаркинг (B0-B3) |
|
|
32
33
|
| Модуль TEST | `.claude/skills/bto/modules/test.md` | Протокол мульти-агентной оценки |
|
|
33
34
|
| Модуль OPTIMIZE | `.claude/skills/bto/modules/optimize.md` | Протокол эволюционной оптимизации |
|
|
34
35
|
| Рубрики судей | `.claude/skills/bto/references/judge-rubrics.md` | Якорные точки для scoring |
|
|
35
36
|
| Паттерны оценки | `.claude/skills/bto/references/eval-patterns.md` | Паттерны мульти-агентной оценки |
|
|
36
37
|
| Методы оптимизации | `.claude/skills/bto/references/optimization-methods.md` | Методология оптимизации |
|
|
37
38
|
| Чеклист качества | `.claude/skills/bto/references/quality-checklist.md` | Детерминистические проверки Layer 0 |
|
|
39
|
+
| Golden samples | `.claude/skills/bto/references/golden-samples.md` | Эталонные структуры для бенчмаркинга |
|
|
38
40
|
| Команда /bto | `.claude/commands/bto.md` | Полный пайплайн |
|
|
39
41
|
| Команда /bto-build | `.claude/commands/bto-build.md` | BUILD-фаза отдельно |
|
|
42
|
+
| Команда /bto-benchmark | `.claude/commands/bto-benchmark.md` | BENCHMARK-фаза отдельно |
|
|
40
43
|
| Команда /bto-test | `.claude/commands/bto-test.md` | TEST-фаза отдельно |
|
|
41
44
|
| Команда /bto-optimize | `.claude/commands/bto-optimize.md` | OPTIMIZE-фаза отдельно |
|
|
42
45
|
| Правила quality gates | `.claude/rules/bto-quality-gates.md` | Автоматически применяемые правила |
|
|
@@ -20,13 +20,14 @@ This guide covers everything you need to use the BTO (Build-Test-Optimize) skill
|
|
|
20
20
|
|
|
21
21
|
## 1. Quick Start (5 minutes)
|
|
22
22
|
|
|
23
|
-
BTO gives you
|
|
23
|
+
BTO gives you five commands. Each can be used independently or together as a pipeline.
|
|
24
24
|
|
|
25
25
|
```
|
|
26
26
|
/bto-build [description] — Generate a new skill, command, rule, or agent template
|
|
27
|
+
/bto-benchmark [path] — Deterministic benchmarking against golden samples
|
|
27
28
|
/bto-test [path] — Evaluate an existing artifact through layered quality gates
|
|
28
29
|
/bto-optimize [path] — Improve an artifact through evolutionary optimization
|
|
29
|
-
/bto [path or description] — Full pipeline: BUILD → TEST → OPTIMIZE
|
|
30
|
+
/bto [path or description] — Full pipeline: BUILD → BENCHMARK → TEST → OPTIMIZE
|
|
30
31
|
```
|
|
31
32
|
|
|
32
33
|
### Your first BTO run
|
|
@@ -577,7 +578,7 @@ BTO does not automatically overwrite your artifact. It presents the optimized ve
|
|
|
577
578
|
|
|
578
579
|
## 5. Full BTO Pipeline with /bto
|
|
579
580
|
|
|
580
|
-
The `/bto` command runs BUILD, TEST, and OPTIMIZE in sequence for a complete quality lifecycle. Use it when starting a new artifact from scratch and wanting production-quality output with minimal manual intervention.
|
|
581
|
+
The `/bto` command runs BUILD, BENCHMARK, TEST, and OPTIMIZE in sequence for a complete quality lifecycle. Use it when starting a new artifact from scratch and wanting production-quality output with minimal manual intervention.
|
|
581
582
|
|
|
582
583
|
### Usage
|
|
583
584
|
|
|
@@ -251,9 +251,10 @@ Note: if convergence is detected after Round 2, Round 3 evaluation is skipped. T
|
|
|
251
251
|
| Stage | Est. tokens |
|
|
252
252
|
|-------|------------:|
|
|
253
253
|
| BUILD (QUICK mode, typical skill) | ~22,000 |
|
|
254
|
+
| BENCHMARK (B0-B3, incl. 3× haiku consistency probe) | ~3,500 |
|
|
254
255
|
| TEST (full, no meta-judge) | ~18,800 |
|
|
255
256
|
| OPTIMIZE (3 rounds) | ~131,000 |
|
|
256
|
-
| **Full /bto pipeline** | **~
|
|
257
|
+
| **Full /bto pipeline** | **~175,500** |
|
|
257
258
|
|
|
258
259
|
For a description-triggered build where DEEP mode is invoked: add approximately 10,000 tokens to the BUILD phase.
|
|
259
260
|
|
|
@@ -19,23 +19,23 @@
|
|
|
19
19
|
|
|
20
20
|
## Обзор системы и философия проектирования
|
|
21
21
|
|
|
22
|
-
`@dzhechkov/skills-bto` — это **Build-Test-Optimize (BTO)** скилл-пак для Claude Code, реализующий полный цикл создания, оценки и итеративного улучшения Claude Code артефактов. Система работает как standalone-инструмент и как интегрированный компонент пайплайна `@dzhechkov/keysarium`.
|
|
22
|
+
`@dzhechkov/skills-bto` — это **Build-Benchmark-Test-Optimize (BTO)** скилл-пак для Claude Code, реализующий полный цикл создания, бенчмаркинга, оценки и итеративного улучшения Claude Code артефактов. Система работает как standalone-инструмент и как интегрированный компонент пайплайна `@dzhechkov/keysarium`.
|
|
23
23
|
|
|
24
24
|
### Фундаментальная идея
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Промпт-инжиниринговые задачи имеют четыре отдельных фазы с принципиально разными требованиями:
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
BUILD TEST OPTIMIZE
|
|
30
|
-
────── ──── ────────
|
|
31
|
-
Генерация Оценка Улучшение
|
|
32
|
-
Требует: Требует: Требует:
|
|
33
|
-
• Творчество • Объективность • Управляемые мутации
|
|
34
|
-
• Структуру • Разные точки зр. • Быструю итерацию
|
|
35
|
-
• Domain знание •
|
|
29
|
+
BUILD BENCHMARK TEST OPTIMIZE
|
|
30
|
+
────── ───────── ──── ────────
|
|
31
|
+
Генерация Бенчмаркинг Оценка Улучшение
|
|
32
|
+
Требует: Требует: Требует: Требует:
|
|
33
|
+
• Творчество • Golden samples • Объективность • Управляемые мутации
|
|
34
|
+
• Структуру • Детерм. тесты • Разные точки зр. • Быструю итерацию
|
|
35
|
+
• Domain знание • Consistency probe • Экспертные судьи • Отбор лучших вариантов
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
BTO изолирует эти
|
|
38
|
+
BTO изолирует эти четыре режима в отдельные модули с чёткими контрактами на входе и выходе. Модули можно запускать независимо или последовательно как пайплайн.
|
|
39
39
|
|
|
40
40
|
### Ключевые принципы проектирования
|
|
41
41
|
|
|
@@ -717,7 +717,7 @@ Variant 3-B ──→ haiku eval ──→ score-3-B.txt ┘
|
|
|
717
717
|
|
|
718
718
|
## Диаграммы потоков данных
|
|
719
719
|
|
|
720
|
-
### Полный BTO пайплайн (BUILD → TEST → OPTIMIZE)
|
|
720
|
+
### Полный BTO пайплайн (BUILD → BENCHMARK → TEST → OPTIMIZE)
|
|
721
721
|
|
|
722
722
|
```mermaid
|
|
723
723
|
flowchart TD
|
|
@@ -947,8 +947,9 @@ flowchart LR
|
|
|
947
947
|
|
|
948
948
|
| Команда | Назначение | Минимальный вход | Стоимость |
|
|
949
949
|
|---------|-----------|-----------------|-----------|
|
|
950
|
-
| `/bto [path]` | Полный пайплайн BUILD→TEST→OPTIMIZE | Путь или описание | ~$0.
|
|
950
|
+
| `/bto [path]` | Полный пайплайн BUILD→BENCHMARK→TEST→OPTIMIZE | Путь или описание | ~$0.16 |
|
|
951
951
|
| `/bto-build [description]` | Только генерация | Текстовое описание | ~$0.01 |
|
|
952
|
+
| `/bto-benchmark [path]` | Детерминистический бенчмаркинг | Путь к артефакту | ~$0.001 |
|
|
952
953
|
| `/bto-test [path]` | Только оценка (full) | Путь к артефакту | ~$0.01 |
|
|
953
954
|
| `/bto-test [path] level=layer0` | Только Layer 0 | Путь к артефакту | $0 |
|
|
954
955
|
| `/bto-test [path] level=layer1` | Layer 0 + haiku | Путь к артефакту | ~$0.001 |
|
|
@@ -118,7 +118,7 @@ Location: `.keysarium/insights/trigger-state.json`
|
|
|
118
118
|
4. Scan all `*.json` files recursively under `.keysarium/memory/` (excluding `config.json`, `reward-summary.json`, `domain-patterns.json`).
|
|
119
119
|
5. Parse each as a RewardRecord (schema defined in `lib/memory-protocol.md`).
|
|
120
120
|
6. Exclude records where `expires_at < current_date`.
|
|
121
|
-
7. Sort by `reward` DESC, then `timestamp` DESC.
|
|
121
|
+
7. Sort by `reward` DESC, then `usage_count` DESC, then `timestamp` DESC. Records with higher usage_count carry more weight in concept graph construction.
|
|
122
122
|
8. Take top 200 records.
|
|
123
123
|
9. If fewer than 5 valid records, exit with status `insufficient_data`.
|
|
124
124
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Core protocol for persistent memory in the Keysarium pipeline. Provides `memory_query()` before tasks and `memory_store()` after tasks.
|
|
4
4
|
|
|
5
|
+
**Protocol version: 1.1** — adds 2-tier index, record lifecycle (HOT/WARM/COLD/PURGE), and brain container manifest.
|
|
6
|
+
|
|
5
7
|
## Memory Namespace
|
|
6
8
|
|
|
7
9
|
All memory files live in `.keysarium/memory/`:
|
|
@@ -9,13 +11,18 @@ All memory files live in `.keysarium/memory/`:
|
|
|
9
11
|
```
|
|
10
12
|
.keysarium/memory/
|
|
11
13
|
├── config.json ← Global configuration
|
|
14
|
+
├── index.json ← 2-tier index (v1.1)
|
|
12
15
|
├── _patterns/
|
|
13
16
|
│ └── domain-patterns.json ← Detected domain patterns
|
|
14
17
|
├── _stats/
|
|
15
|
-
│
|
|
18
|
+
│ ├── reward-summary.json ← Aggregate statistics
|
|
19
|
+
│ └── imported-baselines.json ← Imported reward baselines
|
|
16
20
|
├── {domain}/ ← banking | retail | enterprise | healthcare
|
|
17
|
-
│
|
|
18
|
-
│
|
|
21
|
+
│ ├── {case-slug}/
|
|
22
|
+
│ │ └── {phase}_{timestamp}.json ← HOT/WARM reward records
|
|
23
|
+
│ └── _archive/ ← COLD compressed records (v1.1)
|
|
24
|
+
│ └── {case-slug}/
|
|
25
|
+
│ └── {phase}_{timestamp}.json ← Archived records
|
|
19
26
|
```
|
|
20
27
|
|
|
21
28
|
## Configuration
|
|
@@ -24,7 +31,7 @@ All memory files live in `.keysarium/memory/`:
|
|
|
24
31
|
|
|
25
32
|
```json
|
|
26
33
|
{
|
|
27
|
-
"version": "1.
|
|
34
|
+
"version": "1.1",
|
|
28
35
|
"retention_days": 90,
|
|
29
36
|
"max_results_per_query": 10,
|
|
30
37
|
"enabled": true,
|
|
@@ -34,10 +41,63 @@ All memory files live in `.keysarium/memory/`:
|
|
|
34
41
|
"good": 0.7,
|
|
35
42
|
"needs_work": 0.3,
|
|
36
43
|
"failed": 0.0
|
|
44
|
+
},
|
|
45
|
+
"tier_hot_days": 30,
|
|
46
|
+
"tier_warm_days": 90,
|
|
47
|
+
"tier_cold_days": 180
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Tier fields (v1.1):** If `tier_hot_days` is absent, fall back to v1.0 behavior (flat `retention_days` with no tiering). When present, `retention_days` is ignored in favor of the tier thresholds.
|
|
52
|
+
|
|
53
|
+
## Index File (v1.1)
|
|
54
|
+
|
|
55
|
+
The index provides a compact catalog of all records, enabling targeted reads instead of full directory scans.
|
|
56
|
+
|
|
57
|
+
### index.json Schema
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"version": "1.0",
|
|
62
|
+
"last_updated": "2026-03-02T14:00:00Z",
|
|
63
|
+
"record_count": 47,
|
|
64
|
+
"by_domain": {
|
|
65
|
+
"banking": {
|
|
66
|
+
"count": 23,
|
|
67
|
+
"slugs": ["case-a", "case-b"],
|
|
68
|
+
"avg_reward": 0.82
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"by_phase": {
|
|
72
|
+
"phase-0": { "count": 8, "avg_reward": 0.91 },
|
|
73
|
+
"phase-2": { "count": 12, "avg_reward": 0.65 }
|
|
74
|
+
},
|
|
75
|
+
"by_skill": {
|
|
76
|
+
"goap-research-ed25519": { "count": 10, "avg_reward": 0.78 }
|
|
77
|
+
},
|
|
78
|
+
"records": {
|
|
79
|
+
"bank_kc_automation_phase-2_2026-03-01T12-30-00": {
|
|
80
|
+
"domain": "banking",
|
|
81
|
+
"phase": "phase-2",
|
|
82
|
+
"slug": "bank_kc_automation",
|
|
83
|
+
"reward": 0.7,
|
|
84
|
+
"skill": "goap-research-ed25519",
|
|
85
|
+
"tier": "hot",
|
|
86
|
+
"usage_count": 0,
|
|
87
|
+
"file": "banking/bank_kc_automation/phase-2_2026-03-01T12-30-00.json",
|
|
88
|
+
"expires_at": "2026-08-28T12:30:00Z"
|
|
89
|
+
}
|
|
37
90
|
}
|
|
38
91
|
}
|
|
39
92
|
```
|
|
40
93
|
|
|
94
|
+
### Index Behavior
|
|
95
|
+
|
|
96
|
+
- **Created:** On first `memory_store()` call when tier config is present (or `index.json` already exists)
|
|
97
|
+
- **Updated:** On every `memory_store()`, archive, and purge operation
|
|
98
|
+
- **Fallback:** If missing, `memory_query()` uses v1.0 full-scan algorithm
|
|
99
|
+
- **Rebuild:** If corrupted, delete `index.json` — it will be recreated on next `memory_store()`
|
|
100
|
+
|
|
41
101
|
## Protocol: memory_query(context)
|
|
42
102
|
|
|
43
103
|
Call at the **start** of each pipeline phase to load relevant historical patterns.
|
|
@@ -56,12 +116,22 @@ Call at the **start** of each pipeline phase to load relevant historical pattern
|
|
|
56
116
|
### Algorithm
|
|
57
117
|
|
|
58
118
|
1. **Check enabled:** Read `.keysarium/memory/config.json`. If `enabled` is false or directory does not exist, return empty list.
|
|
59
|
-
2. **
|
|
60
|
-
|
|
119
|
+
2. **Read index (v1.1):** If `.keysarium/memory/index.json` exists, read it and filter `records` entries by `domain` + `phase`. Go to step 2a. If index does not exist, fall back to step 3 (v1.0 full scan).
|
|
120
|
+
- 2a. **Index hit:** If filtered record count ≤ `max_results_per_query`, read only those files by `file` path (targeted read). Go to step 4.
|
|
121
|
+
- 2b. **Index overflow:** If filtered count > limit, rank by `reward` from index entries, select top-N `file` paths, read those files. Go to step 4.
|
|
122
|
+
3. **Full scan (fallback):** Construct `.keysarium/memory/{domain}/` (scan all slugs). Read all `{phase}_*.json` files matching the requested phase.
|
|
61
123
|
4. **Filter expired:** Exclude records where `expires_at < current_date`.
|
|
62
|
-
5. **
|
|
63
|
-
|
|
64
|
-
|
|
124
|
+
5. **Archive old records (v1.1):** If tier config is present, check record ages. For records older than `tier_warm_days`:
|
|
125
|
+
- Read full record
|
|
126
|
+
- Generate `summary` from `reward_reason` + `outcome.checkpoint_response` (first 200 chars)
|
|
127
|
+
- Write compressed record to `.keysarium/memory/{domain}/_archive/{slug}/{filename}`
|
|
128
|
+
- Delete original file from active directory
|
|
129
|
+
- Update `index.json`: set `tier` to `"cold"`, update `file` path
|
|
130
|
+
- Log: "Archived {count} records to cold storage in {domain}"
|
|
131
|
+
6. **Purge ancient records (v1.1):** Delete records from `_archive/` older than `tier_cold_days`. In v1.0 mode, delete records where `expires_at < current_date`. Update `index.json`. Log: "Purged {count} expired records from {domain}"
|
|
132
|
+
7. **Sort:** By `reward` DESC, then `usage_count` DESC, then `timestamp` DESC. HOT and WARM records first; COLD records included only if result count < `max_results_per_query`. Records with higher usage_count are more battle-tested and should be preferred when rewards are equal.
|
|
133
|
+
8. **Limit:** Return top `max_results_per_query` records (default 10).
|
|
134
|
+
9. **Enrich:** Also load `.keysarium/memory/_patterns/domain-patterns.json` for matching domain patterns.
|
|
65
135
|
|
|
66
136
|
### Output
|
|
67
137
|
|
|
@@ -98,6 +168,7 @@ After calling `memory_query()`, the agent should:
|
|
|
98
168
|
2. If `records` is non-empty, review the top 3 records for relevant approaches
|
|
99
169
|
3. If `patterns` is non-empty, apply actionable advice to current phase execution
|
|
100
170
|
4. If both are empty (first run), proceed normally
|
|
171
|
+
5. **Increment usage_count:** For each record actually applied (top 3), increment `usage_count` in both the record file and the index entry. Records with higher usage_count are more proven — prioritize them in future queries.
|
|
101
172
|
|
|
102
173
|
## Protocol: memory_store(result, reward)
|
|
103
174
|
|
|
@@ -136,17 +207,25 @@ Call at each **checkpoint** after the user responds, to persist the phase outcom
|
|
|
136
207
|
|
|
137
208
|
1. **Ensure directory exists:** Create `.keysarium/memory/{domain}/{slug}/` if it does not exist.
|
|
138
209
|
2. **Build record:** Construct full RewardRecord JSON from input.
|
|
139
|
-
3. **Compute expires_at:**
|
|
210
|
+
3. **Compute expires_at:** If tier config is present, use `tier_cold_days` (default 180 days). Otherwise, use `retention_days` (default 90 days). Formula: `current_date + threshold`.
|
|
140
211
|
4. **Generate filename:** `{phase}_{ISO-timestamp}.json` (e.g., `phase-2_2026-03-01T12-30-00.json`).
|
|
141
212
|
5. **Write file:** Write JSON to `.keysarium/memory/{domain}/{slug}/{filename}`.
|
|
142
|
-
6. **
|
|
213
|
+
6. **Update index (v1.1):** Read `.keysarium/memory/index.json` (or create if absent and tier config is present):
|
|
214
|
+
- Add record entry to `records` map: key = record id, value = `{domain, phase, slug, reward, skill, tier: "hot", usage_count: 0, file, expires_at}`
|
|
215
|
+
- Increment `record_count`
|
|
216
|
+
- Update `by_domain` aggregate: increment count, add slug if new, recalculate `avg_reward`
|
|
217
|
+
- Update `by_phase` aggregate: increment count, recalculate `avg_reward`
|
|
218
|
+
- Update `by_skill` aggregate: increment count, recalculate `avg_reward`
|
|
219
|
+
- Set `last_updated` to current timestamp
|
|
220
|
+
- Write updated `index.json`
|
|
221
|
+
7. **Log:** "Stored reward {reward} ({reward_label}) for {phase} of {slug}"
|
|
143
222
|
|
|
144
223
|
### RewardRecord JSON Schema
|
|
145
224
|
|
|
146
225
|
```json
|
|
147
226
|
{
|
|
148
227
|
"id": "bank_kc_automation_phase-2_2026-03-01T12-30-00",
|
|
149
|
-
"version": "1.
|
|
228
|
+
"version": "1.1",
|
|
150
229
|
"timestamp": "2026-03-01T12:30:00Z",
|
|
151
230
|
"case_slug": "bank_kc_automation",
|
|
152
231
|
"domain": "banking",
|
|
@@ -171,10 +250,47 @@ Call at each **checkpoint** after the user responds, to persist the phase outcom
|
|
|
171
250
|
"promise_emitted": "RESEARCH_PARANOID_PASSED"
|
|
172
251
|
},
|
|
173
252
|
"promise_tag": "RESEARCH_PARANOID_PASSED",
|
|
174
|
-
"
|
|
253
|
+
"usage_count": 0,
|
|
254
|
+
"expires_at": "2026-08-28T12:30:00Z"
|
|
175
255
|
}
|
|
176
256
|
```
|
|
177
257
|
|
|
258
|
+
## Record Lifecycle (v1.1)
|
|
259
|
+
|
|
260
|
+
Records transition through tiers based on age:
|
|
261
|
+
|
|
262
|
+
| Tier | Age Range | Location | Fields |
|
|
263
|
+
|------|-----------|----------|--------|
|
|
264
|
+
| **HOT** | 0 – 30 days | `{domain}/{slug}/` | All fields |
|
|
265
|
+
| **WARM** | 30 – 90 days | `{domain}/{slug}/` | All fields (deprioritized in search) |
|
|
266
|
+
| **COLD** | 90 – 180 days | `{domain}/_archive/{slug}/` | Compressed (see below) |
|
|
267
|
+
| **PURGE** | > 180 days | Deleted | — |
|
|
268
|
+
|
|
269
|
+
Tier thresholds are configurable via `config.json` fields: `tier_hot_days`, `tier_warm_days`, `tier_cold_days`.
|
|
270
|
+
|
|
271
|
+
### COLD Record Schema (compressed)
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"id": "bank_kc_automation_phase-2_2026-01-01T12-00-00",
|
|
276
|
+
"phase": "phase-2",
|
|
277
|
+
"domain": "banking",
|
|
278
|
+
"slug": "bank_kc_automation",
|
|
279
|
+
"reward": 0.7,
|
|
280
|
+
"reward_label": "good",
|
|
281
|
+
"skill_used": "goap-research-ed25519",
|
|
282
|
+
"promise_tag": "RESEARCH_PARANOID_PASSED",
|
|
283
|
+
"usage_count": 3,
|
|
284
|
+
"summary": "User requested minor edits to competitor analysis section. ok, but expand the FinTech competitor section",
|
|
285
|
+
"archived_at": "2026-03-02T14:00:00Z",
|
|
286
|
+
"original_timestamp": "2026-01-01T12:00:00Z"
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Backward Compatibility
|
|
291
|
+
|
|
292
|
+
If `tier_hot_days` is NOT present in `config.json`, the lifecycle system is disabled. Records use the v1.0 flat `retention_days` for expiration. No archiving occurs.
|
|
293
|
+
|
|
178
294
|
## Reward Assignment Rules
|
|
179
295
|
|
|
180
296
|
The reward score is determined by the user's response at the checkpoint:
|
|
@@ -193,15 +309,6 @@ The reward score is determined by the user's response at the checkpoint:
|
|
|
193
309
|
- **Positive feedback with minor note** ("great, just fix the typo in section 3") = 1.0
|
|
194
310
|
- **No explicit response** (session ends) = do not store (no record created)
|
|
195
311
|
|
|
196
|
-
## Purge Protocol
|
|
197
|
-
|
|
198
|
-
To prevent unbounded growth, expired records should be cleaned up:
|
|
199
|
-
|
|
200
|
-
1. **Trigger:** At each `memory_query()` call, check for expired records
|
|
201
|
-
2. **Scan:** Within the queried domain directory, find records where `expires_at < current_date`
|
|
202
|
-
3. **Delete:** Remove expired JSON files
|
|
203
|
-
4. **Log:** "Purged {count} expired records from {domain}"
|
|
204
|
-
|
|
205
312
|
## Error Handling
|
|
206
313
|
|
|
207
314
|
| Error | Behavior |
|
|
@@ -211,6 +318,8 @@ To prevent unbounded growth, expired records should be cleaned up:
|
|
|
211
318
|
| Malformed JSON file | Skip that record, log warning, continue |
|
|
212
319
|
| Write fails (permissions, disk) | Log error, continue pipeline without storing |
|
|
213
320
|
| Domain not in `known_domains` | Use "unknown" as domain directory |
|
|
321
|
+
| `index.json` corrupted | Delete and rebuild on next `memory_store()` call |
|
|
322
|
+
| Archive directory write fails | Log warning, keep record in active directory |
|
|
214
323
|
|
|
215
324
|
## Integration with Brain Export
|
|
216
325
|
|
|
@@ -86,12 +86,14 @@ Group records by `skill_used` and cross-reference with domain:
|
|
|
86
86
|
"goap-research-ed25519": {
|
|
87
87
|
"overall_avg": 0.74,
|
|
88
88
|
"total_runs": 15,
|
|
89
|
+
"total_usage_count": 42,
|
|
89
90
|
"by_domain": {
|
|
90
|
-
"banking": { "avg": 0.65, "runs": 8 },
|
|
91
|
-
"retail": { "avg": 0.85, "runs": 7 }
|
|
91
|
+
"banking": { "avg": 0.65, "runs": 8, "usage_count": 18 },
|
|
92
|
+
"retail": { "avg": 0.85, "runs": 7, "usage_count": 24 }
|
|
92
93
|
},
|
|
93
94
|
"best_domain": "retail",
|
|
94
|
-
"worst_domain": "banking"
|
|
95
|
+
"worst_domain": "banking",
|
|
96
|
+
"most_reused_domain": "retail"
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
```
|
|
@@ -110,6 +112,7 @@ Analyze accumulated data to detect actionable patterns. Each pattern has a confi
|
|
|
110
112
|
| Improving Trend | Trend = "improving" for phase in domain | "{phase} quality is improving in {domain} domain" |
|
|
111
113
|
| Degrading Trend | Trend = "degrading" for phase in domain | "{phase} quality is degrading in {domain} -- investigate" |
|
|
112
114
|
| Time Overhead | Phase avg iterations > 2.0 in domain | "{domain} cases require more iterations in {phase}" |
|
|
115
|
+
| High Reuse | Record usage_count >= 5 | "Pattern from {slug}/{phase} is highly reused ({count} times) — consider promoting to a rule" |
|
|
113
116
|
|
|
114
117
|
**Confidence Calculation:**
|
|
115
118
|
```
|