@dzhechkov/keysarium 1.1.2 → 1.2.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/package.json +10 -2
- package/templates/.claude/commands/dream.md +101 -0
- package/templates/.claude/commands/feature-adr.md +92 -0
- package/templates/.claude/commands/init-platform.md +161 -0
- package/templates/.claude/commands/learning-stats.md +130 -0
- package/templates/.claude/commands/workers.md +140 -0
- package/templates/.claude/rules/background-workers.md +72 -0
- package/templates/.claude/rules/dream-cycles.md +90 -0
- package/templates/.claude/rules/feature-adr-conventions.md +82 -0
- package/templates/.claude/rules/reward-learning.md +124 -0
- package/templates/.claude/shards/feature-adr.shard.md +98 -0
- package/templates/.claude/skills/feature-adr/SKILL.md +252 -0
- package/templates/.claude/skills/feature-adr/examples/sample-feature-output.md +257 -0
- package/templates/.claude/skills/feature-adr/modules/00-complexity-router.md +114 -0
- package/templates/.claude/skills/feature-adr/modules/01-requirements.md +113 -0
- package/templates/.claude/skills/feature-adr/modules/02-research.md +92 -0
- package/templates/.claude/skills/feature-adr/modules/03-adr.md +135 -0
- package/templates/.claude/skills/feature-adr/modules/04-ddd.md +114 -0
- package/templates/.claude/skills/feature-adr/modules/05-architecture.md +149 -0
- package/templates/.claude/skills/feature-adr/modules/06-implementation-plan.md +129 -0
- package/templates/.claude/skills/feature-adr/modules/07-code.md +126 -0
- package/templates/.claude/skills/feature-adr/modules/08-qe.md +167 -0
- package/templates/.claude/skills/feature-adr/references/adr-template.md +102 -0
- package/templates/.claude/skills/feature-adr/references/c4-template.md +120 -0
- package/templates/.claude/skills/feature-adr/references/complexity-matrix.md +139 -0
- package/templates/.claude/skills/feature-adr/references/qe-checklist.md +86 -0
- package/templates/CLAUDE.md +124 -3
- package/templates/docs/improvement-directions.md +16 -16
- package/templates/docs/keysarium/01-deployment-guide.md +21 -12
- package/templates/docs/keysarium/02-admin-guide.md +204 -3
- package/templates/docs/keysarium/03-user-guide.md +224 -0
- package/templates/docs/keysarium/05-architecture.md +181 -0
- package/templates/docs/keysarium/06-user-flows.md +235 -0
- package/templates/lib/background-workers.md +278 -0
- package/templates/lib/dream-engine.md +460 -0
- package/templates/lib/judge-attestation.md +322 -0
- package/templates/lib/memory-protocol.md +239 -0
- package/templates/lib/platform-adapters.md +100 -0
- package/templates/lib/platform-templates/copilot.md +134 -0
- package/templates/lib/platform-templates/cursor.md +95 -0
- package/templates/lib/platform-templates/opencode.md +155 -0
- package/templates/lib/reward-tracker.md +256 -0
- package/templates/lib/witness-chain.md +372 -0
- package/templates/lib/worker-templates/brain-export.md +187 -0
- package/templates/lib/worker-templates/consolidate.md +180 -0
- package/templates/lib/worker-templates/dream-cycle.md +154 -0
- package/templates/lib/worker-templates/health-check.md +255 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# GitHub Copilot Platform Template
|
|
2
|
+
|
|
3
|
+
> Generates `.github/copilot-instructions.md` from `.claude/` sources.
|
|
4
|
+
|
|
5
|
+
## Target Format
|
|
6
|
+
|
|
7
|
+
GitHub Copilot reads custom instructions from `.github/copilot-instructions.md`. This is a single markdown file that provides project-level context and instructions to Copilot's AI assistant.
|
|
8
|
+
|
|
9
|
+
## Generation Protocol
|
|
10
|
+
|
|
11
|
+
### Step 1: Generate `.github/copilot-instructions.md`
|
|
12
|
+
|
|
13
|
+
Create `.github/copilot-instructions.md` with the following structure:
|
|
14
|
+
|
|
15
|
+
```markdown
|
|
16
|
+
# {Project Name} — Copilot Instructions
|
|
17
|
+
|
|
18
|
+
> Auto-generated from .claude/ directory by /init-platform. Source of truth: .claude/
|
|
19
|
+
|
|
20
|
+
## Project Overview
|
|
21
|
+
|
|
22
|
+
{Extract the project description from CLAUDE.md:
|
|
23
|
+
- Purpose (2-3 sentences)
|
|
24
|
+
- Key concepts (pipeline phases, skills, research methodology)
|
|
25
|
+
- Project structure overview (simplified directory tree)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
## Core Rules
|
|
29
|
+
|
|
30
|
+
{For each file in .claude/rules/, create a subsection:}
|
|
31
|
+
|
|
32
|
+
### {Rule Name}
|
|
33
|
+
|
|
34
|
+
{Summarize the rule to 5-10 key bullet points.
|
|
35
|
+
Focus on actionable instructions.
|
|
36
|
+
Omit implementation details specific to Claude Code.
|
|
37
|
+
Preserve critical constraints (PARANOID mode, mandatory phases, etc.)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Skills Reference
|
|
43
|
+
|
|
44
|
+
{For each skill in .claude/skills/:}
|
|
45
|
+
|
|
46
|
+
### {Skill Name}
|
|
47
|
+
|
|
48
|
+
**Purpose:** {One-line description}
|
|
49
|
+
|
|
50
|
+
**When to use:** {Extract the "When" or trigger conditions}
|
|
51
|
+
|
|
52
|
+
**Key protocol:**
|
|
53
|
+
{Numbered list of 3-5 core steps from the skill's protocol section.
|
|
54
|
+
Simplify each step to 1-2 sentences.
|
|
55
|
+
Omit tool-specific references.}
|
|
56
|
+
|
|
57
|
+
**Quality gates:**
|
|
58
|
+
{2-4 key quality checks from the skill}
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Pipeline Overview
|
|
63
|
+
|
|
64
|
+
{Simplified version of the phase pipeline:}
|
|
65
|
+
|
|
66
|
+
| Phase | Purpose | Key Output |
|
|
67
|
+
|-------|---------|------------|
|
|
68
|
+
{One row per phase, extracted from CLAUDE.md pipeline table}
|
|
69
|
+
|
|
70
|
+
## Anti-Patterns to Avoid
|
|
71
|
+
|
|
72
|
+
{Extract the anti-patterns table, keeping the Pattern and Required Fix columns}
|
|
73
|
+
|
|
74
|
+
## Domain-Specific Guidance
|
|
75
|
+
|
|
76
|
+
{Summarize domain rules from .claude/rules/domain-specific.md:
|
|
77
|
+
- Banking: key constraints
|
|
78
|
+
- Retail: key constraints
|
|
79
|
+
- Enterprise: key constraints
|
|
80
|
+
Keep each domain to 3-4 bullet points.}
|
|
81
|
+
|
|
82
|
+
## File Conventions
|
|
83
|
+
|
|
84
|
+
{Extract key file naming and directory conventions from .claude/rules/file-conventions.md}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 2: Size Check
|
|
88
|
+
|
|
89
|
+
After generation, verify:
|
|
90
|
+
- `.github/copilot-instructions.md` is under 8,000 tokens (~6,000 words)
|
|
91
|
+
- If over limit, prioritize in this order:
|
|
92
|
+
1. Core Rules (keep all)
|
|
93
|
+
2. Anti-Patterns (keep all)
|
|
94
|
+
3. Skills Reference (summarize further)
|
|
95
|
+
4. Pipeline Overview (keep)
|
|
96
|
+
5. Domain-Specific Guidance (trim to most relevant domain)
|
|
97
|
+
|
|
98
|
+
### Step 3: Ensure `.github/` Directory Exists
|
|
99
|
+
|
|
100
|
+
If `.github/` directory does not exist, create it. If `copilot-instructions.md` already exists, warn the user and generate to `copilot-instructions.generated.md` instead.
|
|
101
|
+
|
|
102
|
+
## Content Adaptation Rules
|
|
103
|
+
|
|
104
|
+
| Source Element | Copilot Adaptation |
|
|
105
|
+
|----------------|---------------------|
|
|
106
|
+
| `Read: .claude/skills/X/SKILL.md` | Summarize inline (no separate files) |
|
|
107
|
+
| Agent tool references | "Break complex tasks into sub-tasks" |
|
|
108
|
+
| Model routing (haiku/sonnet/opus) | Omit entirely (Copilot uses its own model) |
|
|
109
|
+
| `$ARGUMENTS` variable | "User-provided context" |
|
|
110
|
+
| Promise tags `<promise>` | Keep as phase completion markers |
|
|
111
|
+
| Checkpoint protocol | "Confirm with user before moving to next phase" |
|
|
112
|
+
| BTO-specific content | Omit or heavily summarize (not relevant for Copilot workflows) |
|
|
113
|
+
| Governance shards | Summarize key constraints only |
|
|
114
|
+
|
|
115
|
+
## Example Output Structure
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
.github/
|
|
119
|
+
└── copilot-instructions.md (single file, <8K tokens)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Copilot-Specific Notes
|
|
123
|
+
|
|
124
|
+
1. **Copilot reads the entire file** on each interaction, so shorter is better
|
|
125
|
+
2. **No directory-based skills** — everything must be in the single markdown file
|
|
126
|
+
3. **Copilot does not support slash commands** — reference commands as "workflows" or "procedures"
|
|
127
|
+
4. **Focus on rules and constraints** — Copilot benefits most from clear do/don't instructions
|
|
128
|
+
5. **Code patterns over prose** — where possible, show code examples instead of lengthy descriptions
|
|
129
|
+
|
|
130
|
+
## Last Verified
|
|
131
|
+
|
|
132
|
+
Platform: GitHub Copilot
|
|
133
|
+
Format version: .github/copilot-instructions.md (2025+)
|
|
134
|
+
Last verified: 2026-03-01
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Cursor Platform Template
|
|
2
|
+
|
|
3
|
+
> Generates `.cursorrules` and optionally `.cursor/skills/` from `.claude/` sources.
|
|
4
|
+
|
|
5
|
+
## Target Format
|
|
6
|
+
|
|
7
|
+
Cursor uses a `.cursorrules` file in the project root. This is a plain-text/markdown file that Cursor's AI reads as project-level instructions. Optionally, `.cursor/skills/` can hold longer skill documents.
|
|
8
|
+
|
|
9
|
+
## Generation Protocol
|
|
10
|
+
|
|
11
|
+
### Step 1: Generate `.cursorrules`
|
|
12
|
+
|
|
13
|
+
Create a file `.cursorrules` in the project root with the following structure:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
# Project: {project name from CLAUDE.md title}
|
|
17
|
+
|
|
18
|
+
## Project Overview
|
|
19
|
+
|
|
20
|
+
{Extract the first 2-3 paragraphs from CLAUDE.md that describe the project purpose}
|
|
21
|
+
|
|
22
|
+
## Rules
|
|
23
|
+
|
|
24
|
+
{For each file in .claude/rules/:}
|
|
25
|
+
|
|
26
|
+
### {Rule file name without extension, title-cased}
|
|
27
|
+
|
|
28
|
+
{Extract the key rules as bullet points. Omit tables and complex formatting.
|
|
29
|
+
Keep each rule to 1-2 lines. Target: 3-8 bullet points per rule file.}
|
|
30
|
+
|
|
31
|
+
## Skills
|
|
32
|
+
|
|
33
|
+
{For each skill in .claude/skills/:}
|
|
34
|
+
|
|
35
|
+
### {Skill name, title-cased}
|
|
36
|
+
|
|
37
|
+
{Read SKILL.md and extract:
|
|
38
|
+
- One-line description (from the skill's header or first paragraph)
|
|
39
|
+
- Core protocol steps (numbered list, 3-5 key steps)
|
|
40
|
+
- Key constraints or quality gates (2-3 bullet points)
|
|
41
|
+
Keep each skill section to 15-30 lines maximum.}
|
|
42
|
+
|
|
43
|
+
## Pipeline
|
|
44
|
+
|
|
45
|
+
{Extract the pipeline phases table from CLAUDE.md, simplified to:
|
|
46
|
+
Phase name | Description | Key output}
|
|
47
|
+
|
|
48
|
+
## Anti-Patterns
|
|
49
|
+
|
|
50
|
+
{Copy the anti-patterns table from CLAUDE.md or .claude/rules/anti-patterns.md}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Step 2: Generate `.cursor/skills/` (for large skills)
|
|
54
|
+
|
|
55
|
+
If any skill's SKILL.md exceeds 200 lines, create a separate file in `.cursor/skills/`:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
.cursor/skills/{skill-name}.md
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Content: the full SKILL.md content, reformatted to remove Claude Code-specific references (like "Read: .claude/skills/..." instructions). Replace with relative references.
|
|
62
|
+
|
|
63
|
+
### Step 3: Size Check
|
|
64
|
+
|
|
65
|
+
After generation, verify:
|
|
66
|
+
- `.cursorrules` is under 10,000 tokens (~7,500 words)
|
|
67
|
+
- If over limit, further summarize skill sections (keep rules intact)
|
|
68
|
+
|
|
69
|
+
## Content Adaptation Rules
|
|
70
|
+
|
|
71
|
+
| Source Element | Cursor Adaptation |
|
|
72
|
+
|----------------|-------------------|
|
|
73
|
+
| `Read: .claude/skills/X/SKILL.md` | Replace with: "Follow the {X} skill protocol" |
|
|
74
|
+
| Agent tool references | Replace with: "For parallel work, break into sub-tasks" |
|
|
75
|
+
| Model routing (haiku/sonnet/opus) | Omit (Cursor uses its own model) |
|
|
76
|
+
| `$ARGUMENTS` variable | Replace with: "User-provided input" |
|
|
77
|
+
| Promise tags `<promise>` | Keep as documentation markers |
|
|
78
|
+
| Checkpoint protocol | Adapt to: "Pause and confirm with user before proceeding" |
|
|
79
|
+
|
|
80
|
+
## Example Output Structure
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
.cursorrules (main instructions file, <10K tokens)
|
|
84
|
+
.cursor/
|
|
85
|
+
└── skills/
|
|
86
|
+
├── reverse-engineering-unicorn.md (full skill, if >200 lines)
|
|
87
|
+
├── bto.md (full skill, if >200 lines)
|
|
88
|
+
└── feature-adr.md (full skill, if >200 lines)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Last Verified
|
|
92
|
+
|
|
93
|
+
Platform: Cursor
|
|
94
|
+
Format version: .cursorrules (2025+)
|
|
95
|
+
Last verified: 2026-03-01
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# OpenCode Platform Template
|
|
2
|
+
|
|
3
|
+
> Generates `.opencode/` directory structure from `.claude/` sources.
|
|
4
|
+
|
|
5
|
+
## Target Format
|
|
6
|
+
|
|
7
|
+
OpenCode uses a `.opencode/` directory in the project root with a `config.yaml` configuration file and skill/rule markdown files. This is the most structurally similar platform to Claude Code's `.claude/` directory.
|
|
8
|
+
|
|
9
|
+
## Generation Protocol
|
|
10
|
+
|
|
11
|
+
### Step 1: Generate `.opencode/config.yaml`
|
|
12
|
+
|
|
13
|
+
Create `.opencode/config.yaml` with the following structure:
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
# OpenCode configuration for {project name}
|
|
17
|
+
# Generated from .claude/ directory by /init-platform
|
|
18
|
+
# Source: product-keysarium-2026
|
|
19
|
+
|
|
20
|
+
project:
|
|
21
|
+
name: "{project name from CLAUDE.md}"
|
|
22
|
+
description: "{first paragraph of CLAUDE.md}"
|
|
23
|
+
|
|
24
|
+
instructions: |
|
|
25
|
+
{Extract the critical rules from CLAUDE.md:
|
|
26
|
+
- File conventions
|
|
27
|
+
- Research quality requirements (PARANOID mode)
|
|
28
|
+
- Checkpoint protocol summary
|
|
29
|
+
- Anti-patterns to avoid
|
|
30
|
+
Keep to 30-50 lines.}
|
|
31
|
+
|
|
32
|
+
skills_dir: ".opencode/skills"
|
|
33
|
+
rules_dir: ".opencode/rules"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Step 2: Generate `.opencode/skills/`
|
|
37
|
+
|
|
38
|
+
For each skill in `.claude/skills/`:
|
|
39
|
+
|
|
40
|
+
Create `.opencode/skills/{skill-name}.md`:
|
|
41
|
+
|
|
42
|
+
```markdown
|
|
43
|
+
# {Skill Name}
|
|
44
|
+
|
|
45
|
+
{Full content of SKILL.md with the following adaptations:}
|
|
46
|
+
|
|
47
|
+
{Replace Claude Code-specific instructions:
|
|
48
|
+
- "Read: .claude/skills/X/SKILL.md" → "See: .opencode/skills/X.md"
|
|
49
|
+
- "Read: .claude/rules/X.md" → "See: .opencode/rules/X.md"
|
|
50
|
+
- Agent tool references → "For parallel work, break into sub-tasks"
|
|
51
|
+
- Model routing references → Omit or note as "model selection is platform-managed"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
{If the skill has references/ directory:
|
|
55
|
+
- Inline key reference content at the bottom under "## References"
|
|
56
|
+
- Or create .opencode/skills/{skill-name}/ directory with reference files
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
{If the skill has modules/ directory:
|
|
60
|
+
- Create .opencode/skills/{skill-name}/ directory
|
|
61
|
+
- Copy module files with path adaptations
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Step 3: Generate `.opencode/rules/`
|
|
66
|
+
|
|
67
|
+
For each rule file in `.claude/rules/`:
|
|
68
|
+
|
|
69
|
+
Create `.opencode/rules/{rule-name}.md`:
|
|
70
|
+
|
|
71
|
+
```markdown
|
|
72
|
+
# {Rule Title}
|
|
73
|
+
|
|
74
|
+
{Full content of the rule file, with minimal adaptation:
|
|
75
|
+
- Replace .claude/ paths with .opencode/ paths
|
|
76
|
+
- Keep tables and structured content intact
|
|
77
|
+
- Remove Claude Code-specific tool references
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Step 4: Generate `.opencode/README.md`
|
|
82
|
+
|
|
83
|
+
Create a brief README explaining the configuration:
|
|
84
|
+
|
|
85
|
+
```markdown
|
|
86
|
+
# OpenCode Configuration
|
|
87
|
+
|
|
88
|
+
This directory was generated from `.claude/` by the `/init-platform` command.
|
|
89
|
+
|
|
90
|
+
## Structure
|
|
91
|
+
|
|
92
|
+
- `config.yaml` — Main configuration
|
|
93
|
+
- `skills/` — Skill definitions (one per file)
|
|
94
|
+
- `rules/` — Project rules (one per file)
|
|
95
|
+
|
|
96
|
+
## Regenerating
|
|
97
|
+
|
|
98
|
+
To regenerate this configuration from updated `.claude/` sources:
|
|
99
|
+
```
|
|
100
|
+
/init-platform --platform opencode
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Source
|
|
104
|
+
|
|
105
|
+
Generated from: .claude/ directory
|
|
106
|
+
Generated on: {date}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Content Adaptation Rules
|
|
110
|
+
|
|
111
|
+
| Source Element | OpenCode Adaptation |
|
|
112
|
+
|----------------|---------------------|
|
|
113
|
+
| `.claude/skills/X/SKILL.md` | `.opencode/skills/X.md` |
|
|
114
|
+
| `.claude/rules/X.md` | `.opencode/rules/X.md` |
|
|
115
|
+
| `.claude/shards/X.md` | `.opencode/shards/X.md` (if shards are included) |
|
|
116
|
+
| `Read: path` instructions | `See: adapted-path` |
|
|
117
|
+
| Agent tool references | "Break into sub-tasks for parallel work" |
|
|
118
|
+
| Model routing (haiku/sonnet/opus) | Omit (platform-managed) |
|
|
119
|
+
| `$ARGUMENTS` variable | "User-provided input" |
|
|
120
|
+
|
|
121
|
+
## Example Output Structure
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
.opencode/
|
|
125
|
+
├── config.yaml
|
|
126
|
+
├── README.md
|
|
127
|
+
├── skills/
|
|
128
|
+
│ ├── explore.md
|
|
129
|
+
│ ├── goap-research-ed25519.md
|
|
130
|
+
│ ├── problem-solver-enhanced.md
|
|
131
|
+
│ ├── frontend-design.md
|
|
132
|
+
│ ├── presentation-storyteller.md
|
|
133
|
+
│ ├── reverse-engineering-unicorn.md
|
|
134
|
+
│ ├── bto.md
|
|
135
|
+
│ └── feature-adr.md
|
|
136
|
+
└── rules/
|
|
137
|
+
├── agent-swarm.md
|
|
138
|
+
├── anti-patterns.md
|
|
139
|
+
├── checkpoint-protocol.md
|
|
140
|
+
├── domain-specific.md
|
|
141
|
+
├── file-conventions.md
|
|
142
|
+
├── modular-reuse.md
|
|
143
|
+
├── research-quality.md
|
|
144
|
+
├── model-routing.md
|
|
145
|
+
├── trust-tiers.md
|
|
146
|
+
├── bto-quality-gates.md
|
|
147
|
+
├── feature-adr-conventions.md
|
|
148
|
+
└── feedback-loops.md
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Last Verified
|
|
152
|
+
|
|
153
|
+
Platform: OpenCode
|
|
154
|
+
Format version: .opencode/ directory (2025+)
|
|
155
|
+
Last verified: 2026-03-01
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Reward Tracker -- Analytics & Pattern Detection
|
|
2
|
+
|
|
3
|
+
Computes aggregate statistics and detects domain patterns from accumulated reward records. Used by `/learning-stats` and by `memory_query()` for pattern enrichment.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Reward Tracker operates on the data stored by the Memory Protocol (`lib/memory-protocol.md`). It reads all RewardRecord JSON files from `.keysarium/memory/` and produces two output artifacts:
|
|
8
|
+
|
|
9
|
+
1. **reward-summary.json** -- aggregate statistics per phase, domain, and skill
|
|
10
|
+
2. **domain-patterns.json** -- detected patterns with confidence scores
|
|
11
|
+
|
|
12
|
+
## Computation Protocol
|
|
13
|
+
|
|
14
|
+
### Step 1: Load All Records
|
|
15
|
+
|
|
16
|
+
1. Scan `.keysarium/memory/` recursively for all `*.json` files (excluding config.json, domain-patterns.json, reward-summary.json).
|
|
17
|
+
2. Parse each JSON file as a RewardRecord.
|
|
18
|
+
3. Exclude records where `expires_at < current_date`.
|
|
19
|
+
4. Collect into a list sorted by `timestamp` DESC.
|
|
20
|
+
|
|
21
|
+
### Step 2: Per-Phase Reward Averages
|
|
22
|
+
|
|
23
|
+
Group records by `phase` and compute:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"phase-0": {
|
|
28
|
+
"avg_reward": 0.85,
|
|
29
|
+
"total_runs": 12,
|
|
30
|
+
"distribution": {
|
|
31
|
+
"excellent": 8,
|
|
32
|
+
"good": 3,
|
|
33
|
+
"needs_work": 1,
|
|
34
|
+
"failed": 0
|
|
35
|
+
},
|
|
36
|
+
"trend": "stable",
|
|
37
|
+
"best_case": "retail_personalization",
|
|
38
|
+
"worst_case": "bank_kc_automation"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Trend Detection Algorithm:**
|
|
44
|
+
1. Split records for each phase into two halves by timestamp (older half, newer half).
|
|
45
|
+
2. Compute average reward for each half.
|
|
46
|
+
3. If newer_avg - older_avg > 0.15 -> "improving"
|
|
47
|
+
4. If older_avg - newer_avg > 0.15 -> "degrading"
|
|
48
|
+
5. Otherwise -> "stable"
|
|
49
|
+
6. Minimum 4 records required for trend detection; otherwise "insufficient_data".
|
|
50
|
+
|
|
51
|
+
### Step 3: Per-Domain Reward Averages
|
|
52
|
+
|
|
53
|
+
Group records by `domain` and compute:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"banking": {
|
|
58
|
+
"avg_reward": 0.72,
|
|
59
|
+
"total_runs": 18,
|
|
60
|
+
"phase_breakdown": {
|
|
61
|
+
"phase-0": 0.85,
|
|
62
|
+
"phase-1": 0.90,
|
|
63
|
+
"phase-2": 0.55,
|
|
64
|
+
"phase-2.5": 0.70,
|
|
65
|
+
"phase-3": 0.65,
|
|
66
|
+
"phase-4": 0.80,
|
|
67
|
+
"phase-5": 0.72
|
|
68
|
+
},
|
|
69
|
+
"bottleneck_phase": "phase-2",
|
|
70
|
+
"strongest_phase": "phase-1"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Bottleneck Detection:**
|
|
76
|
+
- Phase with the lowest average reward in a domain is flagged as `bottleneck_phase`.
|
|
77
|
+
- Phase with the highest average reward is flagged as `strongest_phase`.
|
|
78
|
+
- Only computed if domain has 3+ records.
|
|
79
|
+
|
|
80
|
+
### Step 4: Per-Skill Effectiveness
|
|
81
|
+
|
|
82
|
+
Group records by `skill_used` and cross-reference with domain:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"goap-research-ed25519": {
|
|
87
|
+
"overall_avg": 0.74,
|
|
88
|
+
"total_runs": 15,
|
|
89
|
+
"by_domain": {
|
|
90
|
+
"banking": { "avg": 0.65, "runs": 8 },
|
|
91
|
+
"retail": { "avg": 0.85, "runs": 7 }
|
|
92
|
+
},
|
|
93
|
+
"best_domain": "retail",
|
|
94
|
+
"worst_domain": "banking"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Step 5: Domain Pattern Detection
|
|
100
|
+
|
|
101
|
+
Analyze accumulated data to detect actionable patterns. Each pattern has a confidence score based on evidence count.
|
|
102
|
+
|
|
103
|
+
**Pattern Detection Rules:**
|
|
104
|
+
|
|
105
|
+
| Rule | Condition | Pattern Template |
|
|
106
|
+
|------|-----------|-----------------|
|
|
107
|
+
| Phase Bottleneck | Phase avg < 0.5 in domain, 3+ records | "{domain} cases struggle in {phase} (avg reward: {avg})" |
|
|
108
|
+
| Phase Excellence | Phase avg > 0.9 in domain, 3+ records | "{domain} cases excel in {phase} (avg reward: {avg})" |
|
|
109
|
+
| Skill-Domain Mismatch | Skill avg < 0.5 in domain but > 0.7 in another | "{skill} underperforms in {domain} vs {other_domain}" |
|
|
110
|
+
| Improving Trend | Trend = "improving" for phase in domain | "{phase} quality is improving in {domain} domain" |
|
|
111
|
+
| Degrading Trend | Trend = "degrading" for phase in domain | "{phase} quality is degrading in {domain} -- investigate" |
|
|
112
|
+
| Time Overhead | Phase avg iterations > 2.0 in domain | "{domain} cases require more iterations in {phase}" |
|
|
113
|
+
|
|
114
|
+
**Confidence Calculation:**
|
|
115
|
+
```
|
|
116
|
+
confidence = min(1.0, evidence_count / 10)
|
|
117
|
+
```
|
|
118
|
+
Where `evidence_count` is the number of records supporting the pattern. Confidence reaches 1.0 at 10+ supporting records.
|
|
119
|
+
|
|
120
|
+
### Step 6: Write Outputs
|
|
121
|
+
|
|
122
|
+
#### reward-summary.json
|
|
123
|
+
|
|
124
|
+
Write to `.keysarium/memory/_stats/reward-summary.json`:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"version": "1.0",
|
|
129
|
+
"generated_at": "2026-03-01T14:00:00Z",
|
|
130
|
+
"total_records": 42,
|
|
131
|
+
"total_domains": 3,
|
|
132
|
+
"total_cases": 8,
|
|
133
|
+
"phase_averages": { ... },
|
|
134
|
+
"domain_averages": { ... },
|
|
135
|
+
"skill_effectiveness": { ... },
|
|
136
|
+
"overall_average": 0.76,
|
|
137
|
+
"overall_trend": "improving"
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### domain-patterns.json
|
|
142
|
+
|
|
143
|
+
Write to `.keysarium/memory/_patterns/domain-patterns.json`:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"version": "1.0",
|
|
148
|
+
"generated_at": "2026-03-01T14:00:00Z",
|
|
149
|
+
"patterns": [
|
|
150
|
+
{
|
|
151
|
+
"pattern_id": "banking-phase2-bottleneck",
|
|
152
|
+
"domain": "banking",
|
|
153
|
+
"description": "Banking cases struggle in Phase 2 (Research) with average reward 0.55",
|
|
154
|
+
"category": "phase_bottleneck",
|
|
155
|
+
"confidence": 0.80,
|
|
156
|
+
"evidence_count": 8,
|
|
157
|
+
"detected_at": "2026-03-01T14:00:00Z",
|
|
158
|
+
"examples": ["bank_kc_automation", "bank_loan_approval"],
|
|
159
|
+
"actionable_advice": "Allocate 20% extra time for Phase 2 in banking cases. Consider pre-loading regulatory templates."
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"pattern_id": "retail-triz-effective",
|
|
163
|
+
"domain": "retail",
|
|
164
|
+
"description": "TRIZ methodology produces better results than Game Theory for retail problem-solving",
|
|
165
|
+
"category": "skill_effectiveness",
|
|
166
|
+
"confidence": 0.60,
|
|
167
|
+
"evidence_count": 6,
|
|
168
|
+
"detected_at": "2026-03-01T14:00:00Z",
|
|
169
|
+
"examples": ["ecom_personalization", "retail_inventory"],
|
|
170
|
+
"actionable_advice": "Prefer TRIZ framework over Game Theory for retail domain cases in Phase 3."
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Display Format for /learning-stats
|
|
177
|
+
|
|
178
|
+
### Phase Averages Table
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
Phase Reward Averages (42 records, 8 cases)
|
|
182
|
+
───────────────────────────────────────────
|
|
183
|
+
Phase | Avg | Runs | Trend |
|
|
184
|
+
────────────|────────|──────|─────────────|
|
|
185
|
+
Phase 0 | 0.85 | 8 | stable |
|
|
186
|
+
Phase 1 | 0.92 | 8 | improving |
|
|
187
|
+
Phase 2 | 0.65 | 7 | stable |
|
|
188
|
+
Phase 2.5 | 0.78 | 6 | improving |
|
|
189
|
+
Phase 3 | 0.71 | 5 | stable |
|
|
190
|
+
Phase 4 | 0.89 | 4 | stable |
|
|
191
|
+
Phase 5 | 0.74 | 4 | stable |
|
|
192
|
+
────────────|────────|──────|─────────────|
|
|
193
|
+
Overall | 0.76 | 42 | improving |
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Domain Breakdown Table
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
Domain Breakdown
|
|
200
|
+
───────────────────────────────────────
|
|
201
|
+
Domain | Avg | Cases | Bottleneck |
|
|
202
|
+
────────────|────────|───────|─────────────|
|
|
203
|
+
Banking | 0.72 | 3 | Phase 2 |
|
|
204
|
+
Retail | 0.82 | 3 | Phase 5 |
|
|
205
|
+
Enterprise | 0.69 | 2 | Phase 3 |
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Detected Patterns
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
Detected Patterns (confidence > 0.5)
|
|
212
|
+
──────────────────────────────────────────────────────
|
|
213
|
+
1. [0.80] Banking cases struggle in Phase 2 (Research)
|
|
214
|
+
Advice: Allocate 20% extra time for Phase 2 in banking cases
|
|
215
|
+
|
|
216
|
+
2. [0.60] TRIZ outperforms Game Theory for retail problem-solving
|
|
217
|
+
Advice: Prefer TRIZ framework for retail domain in Phase 3
|
|
218
|
+
|
|
219
|
+
3. [0.55] Phase 1 quality is improving across all domains
|
|
220
|
+
Advice: Current exploration approach is working well
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Skill Effectiveness Table
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
Skill Effectiveness
|
|
227
|
+
────────────────────────────────────────────────────
|
|
228
|
+
Skill | Avg | Best Domain |
|
|
229
|
+
───────────────────────────────|──────|─────────────|
|
|
230
|
+
explore | 0.92 | retail |
|
|
231
|
+
goap-research-ed25519 | 0.74 | retail |
|
|
232
|
+
problem-solver-enhanced | 0.71 | enterprise |
|
|
233
|
+
reverse-engineering-unicorn | 0.85 | banking |
|
|
234
|
+
presentation-storyteller | 0.74 | retail |
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Empty State
|
|
238
|
+
|
|
239
|
+
When no records exist yet:
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
Learning Stats
|
|
243
|
+
──────────────
|
|
244
|
+
No reward data found in .keysarium/memory/
|
|
245
|
+
|
|
246
|
+
To start collecting data:
|
|
247
|
+
1. Run a case with /casarium
|
|
248
|
+
2. Respond at each checkpoint
|
|
249
|
+
3. Rewards are automatically tracked
|
|
250
|
+
|
|
251
|
+
Memory directory: .keysarium/memory/ (will be created on first run)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Modular Reuse
|
|
255
|
+
|
|
256
|
+
This tracker is domain-agnostic. It works with any RewardRecord JSON that conforms to the schema defined in `lib/memory-protocol.md`. The pattern detection rules can be extended by adding entries to the Pattern Detection Rules table.
|