@dzhechkov/keysarium 1.1.2 → 1.3.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 +7 -2
- package/package.json +10 -2
- package/templates/.claude/commands/brain-export.md +97 -20
- package/templates/.claude/commands/brain-import.md +75 -4
- 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 +135 -8
- 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 +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/docs/keysarium-core/01-architecture.md +559 -0
- package/templates/docs/keysarium-core/02-functionality.md +953 -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/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 +344 -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,187 @@
|
|
|
1
|
+
# Worker Template: Brain Export
|
|
2
|
+
|
|
3
|
+
> This file is loaded by the background worker agent. It contains the complete
|
|
4
|
+
> instructions for executing a non-blocking brain export.
|
|
5
|
+
|
|
6
|
+
## Worker Identity
|
|
7
|
+
|
|
8
|
+
- **Type:** export-brain
|
|
9
|
+
- **Model:** haiku
|
|
10
|
+
- **Purpose:** Non-blocking version of /brain-export. Assembles a portable brain container.
|
|
11
|
+
|
|
12
|
+
## Instructions
|
|
13
|
+
|
|
14
|
+
You are a background worker agent. Your job is to export Keysarium's accumulated
|
|
15
|
+
knowledge into a portable JSON brain container. You operate in ISOLATION -- you must
|
|
16
|
+
not modify any files outside your output directory.
|
|
17
|
+
|
|
18
|
+
### Input Parameters
|
|
19
|
+
|
|
20
|
+
These will be injected by the orchestrator:
|
|
21
|
+
|
|
22
|
+
- `WORKER_ID`: Your unique worker identifier
|
|
23
|
+
- `OUTPUT_DIR`: Your output directory path (`.keysarium/workers/{WORKER_ID}/`)
|
|
24
|
+
|
|
25
|
+
### Execution Steps
|
|
26
|
+
|
|
27
|
+
#### Step 1: Initialize
|
|
28
|
+
|
|
29
|
+
Write your status file:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"worker_id": "{WORKER_ID}",
|
|
34
|
+
"type": "export-brain",
|
|
35
|
+
"status": "running",
|
|
36
|
+
"started_at": "{current ISO8601 timestamp}",
|
|
37
|
+
"completed_at": null,
|
|
38
|
+
"progress": { "phase": "initializing", "items_processed": 0 },
|
|
39
|
+
"error": null
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Step 2: Collect Skill Metadata
|
|
44
|
+
|
|
45
|
+
For each skill in `.claude/skills/`:
|
|
46
|
+
|
|
47
|
+
1. Read `SKILL.md` -- extract name, description, trust_tier
|
|
48
|
+
2. Count files in references/, modules/, examples/
|
|
49
|
+
3. Build skill metadata entry
|
|
50
|
+
|
|
51
|
+
Update status: `"phase": "collecting skill metadata"`
|
|
52
|
+
|
|
53
|
+
**Check for `stop-requested` file.**
|
|
54
|
+
|
|
55
|
+
#### Step 3: Collect Domain Patterns
|
|
56
|
+
|
|
57
|
+
1. Read `TOOLKIT_HARVEST.md` if it exists -- extract all patterns
|
|
58
|
+
2. Read `.claude/rules/domain-specific.md` -- extract domain templates
|
|
59
|
+
3. Scan `researches/` directories for domain distribution
|
|
60
|
+
|
|
61
|
+
Update status: `"phase": "collecting domain patterns"`
|
|
62
|
+
|
|
63
|
+
**Check for `stop-requested` file.**
|
|
64
|
+
|
|
65
|
+
#### Step 4: Collect Research Summaries
|
|
66
|
+
|
|
67
|
+
For each completed research in `researches/`:
|
|
68
|
+
|
|
69
|
+
1. Read `08_executive_summary.md` (if exists) -- extract key summary
|
|
70
|
+
2. Read `README.md` (if exists) -- extract brief
|
|
71
|
+
3. Build research summary entry (NO full content, just metadata + summary)
|
|
72
|
+
|
|
73
|
+
Update status: `"phase": "collecting research summaries"`
|
|
74
|
+
|
|
75
|
+
**Check for `stop-requested` file.**
|
|
76
|
+
|
|
77
|
+
#### Step 5: Collect Harvest Patterns
|
|
78
|
+
|
|
79
|
+
1. Read `TOOLKIT_HARVEST.md` -- extract classified patterns
|
|
80
|
+
2. Categories: skills, commands, rules, templates, patterns, snippets
|
|
81
|
+
|
|
82
|
+
Update status: `"phase": "collecting harvest patterns"`
|
|
83
|
+
|
|
84
|
+
#### Step 6: Collect Pipeline Metrics
|
|
85
|
+
|
|
86
|
+
1. Count total researches (completed vs incomplete)
|
|
87
|
+
2. Count total features (completed vs in-progress)
|
|
88
|
+
3. List skill trust tiers
|
|
89
|
+
4. Summarize domain distribution
|
|
90
|
+
|
|
91
|
+
Update status: `"phase": "collecting pipeline metrics"`
|
|
92
|
+
|
|
93
|
+
#### Step 7: Assemble Brain Container
|
|
94
|
+
|
|
95
|
+
Write `{OUTPUT_DIR}/output/brain-export-{YYYYMMDD}.json`:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"version": "1.0",
|
|
100
|
+
"format": "keysarium-brain",
|
|
101
|
+
"exported_at": "{ISO8601 timestamp}",
|
|
102
|
+
"source_project": "product-keysarium-2026",
|
|
103
|
+
"worker_id": "{WORKER_ID}",
|
|
104
|
+
"skills": [
|
|
105
|
+
{
|
|
106
|
+
"name": "explore",
|
|
107
|
+
"description": "Adaptive task clarification",
|
|
108
|
+
"trust_tier": 1,
|
|
109
|
+
"trust_label": "Structured",
|
|
110
|
+
"has_references": true,
|
|
111
|
+
"has_modules": false,
|
|
112
|
+
"has_examples": false
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
"domain_patterns": [
|
|
116
|
+
{
|
|
117
|
+
"domain": "banking",
|
|
118
|
+
"rules": ["on-premise LLM", "HITL mandatory", "FZ-152 compliance"],
|
|
119
|
+
"palette": "Blue/Navy/Silver"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"research_summaries": [
|
|
123
|
+
{
|
|
124
|
+
"slug": "bank_kc_automation",
|
|
125
|
+
"domain": "banking",
|
|
126
|
+
"status": "completed",
|
|
127
|
+
"summary": "AI-powered knowledge center automation for banking..."
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"harvest_patterns": {
|
|
131
|
+
"skills_count": 0,
|
|
132
|
+
"commands_count": 0,
|
|
133
|
+
"rules_count": 0,
|
|
134
|
+
"patterns_count": 0,
|
|
135
|
+
"patterns": []
|
|
136
|
+
},
|
|
137
|
+
"pipeline_metrics": {
|
|
138
|
+
"total_researches": 5,
|
|
139
|
+
"completed_researches": 3,
|
|
140
|
+
"total_features": 2,
|
|
141
|
+
"completed_features": 1,
|
|
142
|
+
"skill_tiers": { "tier_0": 1, "tier_1": 6, "tier_2": 0, "tier_3": 0 },
|
|
143
|
+
"domain_distribution": { "banking": 2, "retail": 1 }
|
|
144
|
+
},
|
|
145
|
+
"metadata": {
|
|
146
|
+
"generator": "background-worker-export-brain",
|
|
147
|
+
"keysarium_version": "2026-03-01"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Step 8: Complete
|
|
153
|
+
|
|
154
|
+
Write final status:
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"worker_id": "{WORKER_ID}",
|
|
159
|
+
"type": "export-brain",
|
|
160
|
+
"status": "completed",
|
|
161
|
+
"started_at": "{start timestamp}",
|
|
162
|
+
"completed_at": "{current timestamp}",
|
|
163
|
+
"progress": { "phase": "completed", "items_processed": 5 },
|
|
164
|
+
"error": null
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Also copy the brain export file to `.keysarium/exports/` if that directory exists
|
|
169
|
+
(create it if needed). This provides a standard location for brain exports regardless
|
|
170
|
+
of which worker produced them.
|
|
171
|
+
|
|
172
|
+
### Error Handling
|
|
173
|
+
|
|
174
|
+
If any collection step fails:
|
|
175
|
+
1. Write partial brain container with available data
|
|
176
|
+
2. Add `"incomplete": true` and `"missing_sections"` to the metadata
|
|
177
|
+
3. Write error details to `{OUTPUT_DIR}/error.log`
|
|
178
|
+
4. Set status to `completed` (partial export is still useful)
|
|
179
|
+
|
|
180
|
+
Only set status to `failed` if the entire worker cannot write output at all.
|
|
181
|
+
|
|
182
|
+
### Isolation Rules
|
|
183
|
+
|
|
184
|
+
- You MUST only write files to `{OUTPUT_DIR}/` and `.keysarium/exports/`
|
|
185
|
+
- You MUST NOT modify any file in `researches/`, `features/`, `.claude/`, or project root
|
|
186
|
+
- You MUST NOT spawn sub-agents
|
|
187
|
+
- You MAY read any file in the project for data collection
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Worker Template: Pattern Consolidation
|
|
2
|
+
|
|
3
|
+
> This file is loaded by the background worker agent. It contains the complete
|
|
4
|
+
> instructions for executing the consolidation task.
|
|
5
|
+
|
|
6
|
+
## Worker Identity
|
|
7
|
+
|
|
8
|
+
- **Type:** consolidate
|
|
9
|
+
- **Model:** sonnet
|
|
10
|
+
- **Purpose:** Scan completed researches for universal patterns and generate a harvest delta
|
|
11
|
+
|
|
12
|
+
## Instructions
|
|
13
|
+
|
|
14
|
+
You are a background worker agent. Your job is to analyze completed research cases
|
|
15
|
+
and extract reusable patterns. You operate in ISOLATION -- you must not modify any
|
|
16
|
+
files outside your output directory.
|
|
17
|
+
|
|
18
|
+
### Input Parameters
|
|
19
|
+
|
|
20
|
+
These will be injected by the orchestrator:
|
|
21
|
+
|
|
22
|
+
- `WORKER_ID`: Your unique worker identifier
|
|
23
|
+
- `OUTPUT_DIR`: Your output directory path (`.keysarium/workers/{WORKER_ID}/`)
|
|
24
|
+
|
|
25
|
+
### Execution Steps
|
|
26
|
+
|
|
27
|
+
#### Step 1: Initialize
|
|
28
|
+
|
|
29
|
+
Write your status file:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
// Write to {OUTPUT_DIR}/status.json
|
|
33
|
+
{
|
|
34
|
+
"worker_id": "{WORKER_ID}",
|
|
35
|
+
"type": "consolidate",
|
|
36
|
+
"status": "running",
|
|
37
|
+
"started_at": "{current ISO8601 timestamp}",
|
|
38
|
+
"completed_at": null,
|
|
39
|
+
"progress": {
|
|
40
|
+
"phase": "initializing",
|
|
41
|
+
"items_processed": 0
|
|
42
|
+
},
|
|
43
|
+
"error": null
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Step 2: Scan Researches
|
|
48
|
+
|
|
49
|
+
1. List all directories under `researches/`
|
|
50
|
+
2. For each research directory, check for completion markers:
|
|
51
|
+
- File `08_executive_summary.md` exists (indicates completed case)
|
|
52
|
+
- File `README.md` exists (indicates packaging done)
|
|
53
|
+
3. Build a list of completed research slugs
|
|
54
|
+
4. Update status: `"phase": "scanning researches", "items_processed": {count}`
|
|
55
|
+
|
|
56
|
+
**IMPORTANT:** Check for `{OUTPUT_DIR}/stop-requested` file. If it exists, write
|
|
57
|
+
status as `stopped` and exit immediately.
|
|
58
|
+
|
|
59
|
+
#### Step 3: Analyze Patterns
|
|
60
|
+
|
|
61
|
+
For each completed research:
|
|
62
|
+
|
|
63
|
+
1. Read `00_product_discovery.md` -- extract domain, JTBD segments
|
|
64
|
+
2. Read `02_research_findings.md` -- extract key findings, technologies
|
|
65
|
+
3. Read `03_solution_strategy.md` -- extract solution patterns
|
|
66
|
+
4. Read `05_presentation_content.md` -- extract storytelling patterns
|
|
67
|
+
|
|
68
|
+
Look for:
|
|
69
|
+
- **Domain patterns**: Which domains appear most? What works in each?
|
|
70
|
+
- **Technology patterns**: Which technologies are recommended repeatedly?
|
|
71
|
+
- **Solution patterns**: Which problem-solving frameworks yield best results?
|
|
72
|
+
- **Anti-patterns**: Which approaches were rejected and why?
|
|
73
|
+
- **Time patterns**: Which phases tend to take longer than budgeted?
|
|
74
|
+
|
|
75
|
+
Update status: `"phase": "analyzing patterns", "items_processed": {count}`
|
|
76
|
+
|
|
77
|
+
**IMPORTANT:** Check for `stop-requested` file between each research analysis.
|
|
78
|
+
|
|
79
|
+
#### Step 4: Generate Output
|
|
80
|
+
|
|
81
|
+
Write the following files to `{OUTPUT_DIR}/output/`:
|
|
82
|
+
|
|
83
|
+
**patterns.json:**
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"generated_at": "{timestamp}",
|
|
87
|
+
"worker_id": "{WORKER_ID}",
|
|
88
|
+
"cases_analyzed": 5,
|
|
89
|
+
"patterns": [
|
|
90
|
+
{
|
|
91
|
+
"type": "domain",
|
|
92
|
+
"name": "Banking cases need on-premise LLM",
|
|
93
|
+
"frequency": 3,
|
|
94
|
+
"confidence": "high",
|
|
95
|
+
"source_cases": ["bank_kc_automation", "bank_risk_scoring"]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "technology",
|
|
99
|
+
"name": "GigaChat preferred for Russian-language banking",
|
|
100
|
+
"frequency": 2,
|
|
101
|
+
"confidence": "medium",
|
|
102
|
+
"source_cases": ["bank_kc_automation"]
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"anti_patterns": [
|
|
106
|
+
{
|
|
107
|
+
"name": "Generic GPT without architecture",
|
|
108
|
+
"occurrences": 1,
|
|
109
|
+
"fix": "Always specify concrete model + pipeline"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"recommendations": [
|
|
113
|
+
"Consider increasing Phase 2 time budget for banking domain (observed 2x overrun)",
|
|
114
|
+
"TRIZ framework shows higher success rate than Game Theory for retail cases"
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**harvest-delta.md:**
|
|
120
|
+
```markdown
|
|
121
|
+
# Harvest Delta — {timestamp}
|
|
122
|
+
|
|
123
|
+
## New Patterns Discovered
|
|
124
|
+
|
|
125
|
+
### Domain Patterns
|
|
126
|
+
- [pattern description with source cases]
|
|
127
|
+
|
|
128
|
+
### Technology Patterns
|
|
129
|
+
- [pattern description with source cases]
|
|
130
|
+
|
|
131
|
+
### Solution Patterns
|
|
132
|
+
- [pattern description with source cases]
|
|
133
|
+
|
|
134
|
+
## Recommendations
|
|
135
|
+
|
|
136
|
+
- [actionable recommendation]
|
|
137
|
+
|
|
138
|
+
## Application Instructions
|
|
139
|
+
|
|
140
|
+
To apply these findings to TOOLKIT_HARVEST.md, review the patterns above and
|
|
141
|
+
manually merge the relevant ones. This worker does NOT modify TOOLKIT_HARVEST.md
|
|
142
|
+
directly to preserve isolation.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Step 5: Complete
|
|
146
|
+
|
|
147
|
+
1. Read `TOOLKIT_HARVEST.md` if it exists -- note its current content for context
|
|
148
|
+
(do NOT modify it)
|
|
149
|
+
2. Write final status:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"worker_id": "{WORKER_ID}",
|
|
154
|
+
"type": "consolidate",
|
|
155
|
+
"status": "completed",
|
|
156
|
+
"started_at": "{start timestamp}",
|
|
157
|
+
"completed_at": "{current timestamp}",
|
|
158
|
+
"progress": {
|
|
159
|
+
"phase": "completed",
|
|
160
|
+
"items_processed": "{total cases analyzed}"
|
|
161
|
+
},
|
|
162
|
+
"error": null
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Error Handling
|
|
167
|
+
|
|
168
|
+
If any step fails:
|
|
169
|
+
|
|
170
|
+
1. Write error details to `{OUTPUT_DIR}/error.log`
|
|
171
|
+
2. Update status.json with status `failed` and error message
|
|
172
|
+
3. Exit
|
|
173
|
+
|
|
174
|
+
### Isolation Rules
|
|
175
|
+
|
|
176
|
+
- You MUST only write files to `{OUTPUT_DIR}/`
|
|
177
|
+
- You MUST NOT modify any file in `researches/`, `features/`, `.claude/`, or project root
|
|
178
|
+
- You MUST NOT modify `TOOLKIT_HARVEST.md` (write delta to your output dir instead)
|
|
179
|
+
- You MUST NOT spawn sub-agents
|
|
180
|
+
- You MAY read any file in the project for analysis purposes
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Worker Template: Dream Cycle
|
|
2
|
+
|
|
3
|
+
> This file is loaded by the background worker agent. It contains the complete
|
|
4
|
+
> instructions for executing a dream cycle using the DreamEngine protocol.
|
|
5
|
+
|
|
6
|
+
## Worker Identity
|
|
7
|
+
|
|
8
|
+
- **Type:** dream-cycle
|
|
9
|
+
- **Model:** sonnet
|
|
10
|
+
- **Purpose:** Build concept graph from reward records, detect cross-domain associations, generate actionable insights
|
|
11
|
+
|
|
12
|
+
## Instructions
|
|
13
|
+
|
|
14
|
+
You are a background worker agent. Your job is to analyze accumulated reward records
|
|
15
|
+
and generate higher-order insights using the DreamEngine protocol defined in
|
|
16
|
+
`lib/dream-engine.md`. You operate in ISOLATION -- you must not modify any files
|
|
17
|
+
outside your output directory and `.keysarium/insights/`.
|
|
18
|
+
|
|
19
|
+
### Input Parameters
|
|
20
|
+
|
|
21
|
+
These will be injected by the orchestrator:
|
|
22
|
+
|
|
23
|
+
- `WORKER_ID`: Your unique worker identifier
|
|
24
|
+
- `OUTPUT_DIR`: Your output directory path (`.keysarium/workers/{WORKER_ID}/`)
|
|
25
|
+
- `TRIGGER_REASON`: Why this dream was triggered (`time` | `volume` | `event` | `manual`)
|
|
26
|
+
|
|
27
|
+
### Execution Steps
|
|
28
|
+
|
|
29
|
+
#### Step 1: Initialize
|
|
30
|
+
|
|
31
|
+
Write your status file:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
// Write to {OUTPUT_DIR}/status.json
|
|
35
|
+
{
|
|
36
|
+
"worker_id": "{WORKER_ID}",
|
|
37
|
+
"type": "dream-cycle",
|
|
38
|
+
"status": "running",
|
|
39
|
+
"started_at": "{current ISO8601 timestamp}",
|
|
40
|
+
"completed_at": null,
|
|
41
|
+
"progress": {
|
|
42
|
+
"phase": "initializing",
|
|
43
|
+
"items_processed": 0
|
|
44
|
+
},
|
|
45
|
+
"error": null
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Step 2: Load Data
|
|
50
|
+
|
|
51
|
+
Follow the DreamEngine Step 1 (Load Data) protocol from `lib/dream-engine.md`:
|
|
52
|
+
|
|
53
|
+
1. Check if `.keysarium/memory/` exists. If not, write status `completed` with `"phase": "no_data"` and exit.
|
|
54
|
+
2. Read `.keysarium/memory/_stats/reward-summary.json` (optional).
|
|
55
|
+
3. Read `.keysarium/memory/_patterns/domain-patterns.json` (optional).
|
|
56
|
+
4. Scan and parse all reward record JSON files under `.keysarium/memory/`.
|
|
57
|
+
5. Exclude expired records, sort by reward DESC, take top 200.
|
|
58
|
+
6. If fewer than 5 records: write status `completed` with `"phase": "insufficient_data"` and exit.
|
|
59
|
+
|
|
60
|
+
Update status: `"phase": "loading data", "items_processed": {record_count}`
|
|
61
|
+
|
|
62
|
+
**IMPORTANT:** Check for `{OUTPUT_DIR}/stop-requested` file. If it exists, write status as `stopped` and exit immediately.
|
|
63
|
+
|
|
64
|
+
#### Step 3: Build Concept Graph
|
|
65
|
+
|
|
66
|
+
Follow the DreamEngine Step 2 (Build Concept Graph) protocol:
|
|
67
|
+
|
|
68
|
+
1. Initialize empty graph.
|
|
69
|
+
2. For each record, create/update domain, phase, skill, and outcome nodes.
|
|
70
|
+
3. Create/update edges with reward weights.
|
|
71
|
+
4. Compute per-node aggregates (avg_reward, record_count, trend).
|
|
72
|
+
5. Compute per-edge aggregates (weight, record_count).
|
|
73
|
+
|
|
74
|
+
Update status: `"phase": "building concept graph", "items_processed": {node_count}`
|
|
75
|
+
|
|
76
|
+
**IMPORTANT:** Check for `stop-requested` file.
|
|
77
|
+
|
|
78
|
+
#### Step 4: Detect Associations
|
|
79
|
+
|
|
80
|
+
Follow the DreamEngine Step 3 (Detect Associations) protocol:
|
|
81
|
+
|
|
82
|
+
1. Cross-domain phase comparison (reward gap > 0.15).
|
|
83
|
+
2. Skill-domain mismatch detection (reward gap > 0.15).
|
|
84
|
+
3. Phase correlation analysis (co-occurring low rewards).
|
|
85
|
+
4. Temporal trend detection (systematic changes over time).
|
|
86
|
+
|
|
87
|
+
Update status: `"phase": "detecting associations", "items_processed": {association_count}`
|
|
88
|
+
|
|
89
|
+
**IMPORTANT:** Check for `stop-requested` file.
|
|
90
|
+
|
|
91
|
+
#### Step 5: Generate Insights
|
|
92
|
+
|
|
93
|
+
Follow the DreamEngine Step 4 (Generate Insights) protocol:
|
|
94
|
+
|
|
95
|
+
1. Convert each association to an Insight object.
|
|
96
|
+
2. Map association types to insight types.
|
|
97
|
+
3. Score confidence and impact.
|
|
98
|
+
4. Add actionable advice to descriptions.
|
|
99
|
+
5. Promote high-confidence domain patterns to insights.
|
|
100
|
+
6. Deduplicate against recent dreams (last 3 files in `.keysarium/insights/`).
|
|
101
|
+
7. Sort by rank_score DESC, take top 20.
|
|
102
|
+
|
|
103
|
+
Update status: `"phase": "generating insights", "items_processed": {insight_count}`
|
|
104
|
+
|
|
105
|
+
#### Step 6: Store Results
|
|
106
|
+
|
|
107
|
+
Follow the DreamEngine Step 5 (Store and Clean) protocol:
|
|
108
|
+
|
|
109
|
+
1. Ensure `.keysarium/insights/` directory exists.
|
|
110
|
+
2. Write dream result JSON to `.keysarium/insights/dream-{YYYYMMDD}-{HHmmss}.json`.
|
|
111
|
+
3. Apply retention: list dream files, keep newest 10, delete older.
|
|
112
|
+
4. Reset trigger state in `.keysarium/insights/trigger-state.json`.
|
|
113
|
+
5. Copy dream result to `{OUTPUT_DIR}/output/dream-{timestamp}.json`.
|
|
114
|
+
|
|
115
|
+
#### Step 7: Complete
|
|
116
|
+
|
|
117
|
+
Write final status:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"worker_id": "{WORKER_ID}",
|
|
122
|
+
"type": "dream-cycle",
|
|
123
|
+
"status": "completed",
|
|
124
|
+
"started_at": "{start timestamp}",
|
|
125
|
+
"completed_at": "{current timestamp}",
|
|
126
|
+
"progress": {
|
|
127
|
+
"phase": "completed",
|
|
128
|
+
"records_analyzed": "{count}",
|
|
129
|
+
"insights_generated": "{count}",
|
|
130
|
+
"associations_found": "{count}"
|
|
131
|
+
},
|
|
132
|
+
"error": null
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Error Handling
|
|
137
|
+
|
|
138
|
+
If any step fails:
|
|
139
|
+
|
|
140
|
+
1. Write error details to `{OUTPUT_DIR}/error.log`
|
|
141
|
+
2. Update status.json with status `failed` and error message in the `error` field
|
|
142
|
+
3. Do NOT modify trigger-state.json on failure (preserve current trigger state)
|
|
143
|
+
4. Exit
|
|
144
|
+
|
|
145
|
+
### Isolation Rules
|
|
146
|
+
|
|
147
|
+
- You MUST only write files to `{OUTPUT_DIR}/` and `.keysarium/insights/`
|
|
148
|
+
- You MUST NOT modify any file in `researches/`, `features/`, `.claude/`, or project root
|
|
149
|
+
- You MUST NOT modify files in `.keysarium/memory/` (read-only access)
|
|
150
|
+
- You MUST NOT modify `TOOLKIT_HARVEST.md` or `CLAUDE.md`
|
|
151
|
+
- You MUST NOT spawn sub-agents
|
|
152
|
+
- You MAY read any file in the project for analysis purposes
|
|
153
|
+
- Exception: `.keysarium/insights/trigger-state.json` is writable (for reset on completion)
|
|
154
|
+
- Exception: `.keysarium/insights/dream-*.json` is writable (for new dream results and retention cleanup)
|