@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.
Files changed (62) hide show
  1. package/README.md +7 -2
  2. package/package.json +10 -2
  3. package/templates/.claude/commands/brain-export.md +97 -20
  4. package/templates/.claude/commands/brain-import.md +75 -4
  5. package/templates/.claude/commands/dream.md +101 -0
  6. package/templates/.claude/commands/feature-adr.md +92 -0
  7. package/templates/.claude/commands/init-platform.md +161 -0
  8. package/templates/.claude/commands/learning-stats.md +130 -0
  9. package/templates/.claude/commands/workers.md +140 -0
  10. package/templates/.claude/rules/background-workers.md +72 -0
  11. package/templates/.claude/rules/dream-cycles.md +90 -0
  12. package/templates/.claude/rules/feature-adr-conventions.md +82 -0
  13. package/templates/.claude/rules/reward-learning.md +124 -0
  14. package/templates/.claude/shards/feature-adr.shard.md +98 -0
  15. package/templates/.claude/skills/feature-adr/SKILL.md +252 -0
  16. package/templates/.claude/skills/feature-adr/examples/sample-feature-output.md +257 -0
  17. package/templates/.claude/skills/feature-adr/modules/00-complexity-router.md +114 -0
  18. package/templates/.claude/skills/feature-adr/modules/01-requirements.md +113 -0
  19. package/templates/.claude/skills/feature-adr/modules/02-research.md +92 -0
  20. package/templates/.claude/skills/feature-adr/modules/03-adr.md +135 -0
  21. package/templates/.claude/skills/feature-adr/modules/04-ddd.md +114 -0
  22. package/templates/.claude/skills/feature-adr/modules/05-architecture.md +149 -0
  23. package/templates/.claude/skills/feature-adr/modules/06-implementation-plan.md +129 -0
  24. package/templates/.claude/skills/feature-adr/modules/07-code.md +126 -0
  25. package/templates/.claude/skills/feature-adr/modules/08-qe.md +167 -0
  26. package/templates/.claude/skills/feature-adr/references/adr-template.md +102 -0
  27. package/templates/.claude/skills/feature-adr/references/c4-template.md +120 -0
  28. package/templates/.claude/skills/feature-adr/references/complexity-matrix.md +139 -0
  29. package/templates/.claude/skills/feature-adr/references/qe-checklist.md +86 -0
  30. package/templates/CLAUDE.md +135 -8
  31. package/templates/docs/feature-adr/01-architecture.md +750 -0
  32. package/templates/docs/feature-adr/02-functionality.md +712 -0
  33. package/templates/docs/feature-adr/03-deployment-guide.md +614 -0
  34. package/templates/docs/feature-adr/04-admin-guide.md +564 -0
  35. package/templates/docs/feature-adr/05-user-guide.md +508 -0
  36. package/templates/docs/feature-adr/06-user-flows.md +1101 -0
  37. package/templates/docs/improvement-directions.md +16 -16
  38. package/templates/docs/keysarium/01-deployment-guide.md +21 -12
  39. package/templates/docs/keysarium/02-admin-guide.md +204 -3
  40. package/templates/docs/keysarium/03-user-guide.md +224 -0
  41. package/templates/docs/keysarium/05-architecture.md +181 -0
  42. package/templates/docs/keysarium/06-user-flows.md +235 -0
  43. package/templates/docs/keysarium-core/01-architecture.md +559 -0
  44. package/templates/docs/keysarium-core/02-functionality.md +953 -0
  45. package/templates/docs/keysarium-core/03-deployment-guide.md +625 -0
  46. package/templates/docs/keysarium-core/04-admin-guide.md +529 -0
  47. package/templates/docs/keysarium-core/05-user-guide.md +599 -0
  48. package/templates/docs/keysarium-core/06-user-flows.md +804 -0
  49. package/templates/lib/background-workers.md +278 -0
  50. package/templates/lib/dream-engine.md +460 -0
  51. package/templates/lib/judge-attestation.md +322 -0
  52. package/templates/lib/memory-protocol.md +344 -0
  53. package/templates/lib/platform-adapters.md +100 -0
  54. package/templates/lib/platform-templates/copilot.md +134 -0
  55. package/templates/lib/platform-templates/cursor.md +95 -0
  56. package/templates/lib/platform-templates/opencode.md +155 -0
  57. package/templates/lib/reward-tracker.md +256 -0
  58. package/templates/lib/witness-chain.md +372 -0
  59. package/templates/lib/worker-templates/brain-export.md +187 -0
  60. package/templates/lib/worker-templates/consolidate.md +180 -0
  61. package/templates/lib/worker-templates/dream-cycle.md +154 -0
  62. package/templates/lib/worker-templates/health-check.md +255 -0
@@ -0,0 +1,161 @@
1
+ ---
2
+ description: "Generate platform-specific configuration for Cursor, OpenCode, or GitHub Copilot"
3
+ argument: "--platform cursor|opencode|copilot|all"
4
+ ---
5
+
6
+ # Init Platform — Multi-Platform Config Generator
7
+
8
+ Generate platform-native configuration files from the existing `.claude/` directory structure.
9
+ Supports Cursor, OpenCode, and GitHub Copilot.
10
+
11
+ ## Protocol
12
+
13
+ ### Step 1: Parse Arguments
14
+
15
+ Parse `$ARGUMENTS` for the `--platform` flag:
16
+
17
+ | Argument | Action |
18
+ |----------|--------|
19
+ | `--platform cursor` | Generate Cursor config only |
20
+ | `--platform opencode` | Generate OpenCode config only |
21
+ | `--platform copilot` | Generate GitHub Copilot config only |
22
+ | `--platform all` | Generate configs for all three platforms |
23
+ | (no argument) | Prompt user to choose a platform |
24
+
25
+ If `$ARGUMENTS` does not contain `--platform`, ask:
26
+ ```
27
+ Which platform(s) to generate config for?
28
+ 1. cursor — .cursorrules + .cursor/skills/
29
+ 2. opencode — .opencode/ directory
30
+ 3. copilot — .github/copilot-instructions.md
31
+ 4. all — all three platforms
32
+ ```
33
+
34
+ ### Step 2: Load Adapter Definitions
35
+
36
+ ```
37
+ Read: lib/platform-adapters.md
38
+ ```
39
+
40
+ This file contains the platform registry: mapping platform names to their template paths,
41
+ output structures, and translation strategies.
42
+
43
+ ### Step 3: Scan Source Content
44
+
45
+ Scan the following directories for content to translate:
46
+
47
+ 1. **Skills:** List all directories in `.claude/skills/`, read each `SKILL.md`
48
+ 2. **Rules:** List all `.md` files in `.claude/rules/`
49
+ 3. **Project context:** Read `CLAUDE.md` for project overview, pipeline description, and anti-patterns
50
+
51
+ Build a content inventory:
52
+ ```
53
+ Skills found: [list skill names]
54
+ Rules found: [list rule file names]
55
+ Project: [project name from CLAUDE.md]
56
+ ```
57
+
58
+ ### Step 4: Check for Existing Configs
59
+
60
+ Before generating, check if target files already exist:
61
+
62
+ | Platform | Check |
63
+ |----------|-------|
64
+ | Cursor | Does `.cursorrules` exist? Does `.cursor/` exist? |
65
+ | OpenCode | Does `.opencode/` exist? |
66
+ | Copilot | Does `.github/copilot-instructions.md` exist? |
67
+
68
+ If any target file exists, warn:
69
+ ```
70
+ Warning: {file} already exists.
71
+ Options:
72
+ - "перезаписать" — overwrite existing config
73
+ - "рядом" — generate as {file}.generated.md
74
+ - "пропустить" — skip this platform
75
+ ```
76
+
77
+ For auto-proceed mode: generate as `.generated.md` variant to avoid data loss.
78
+
79
+ ### Step 5: Generate Platform Configs
80
+
81
+ For each selected platform, load the corresponding template and follow its generation protocol:
82
+
83
+ #### Cursor
84
+ ```
85
+ Read: lib/platform-templates/cursor.md
86
+ ```
87
+ Follow the template to generate:
88
+ - `.cursorrules` (main instructions, <10K tokens)
89
+ - `.cursor/skills/` (optional, for large skills >200 lines)
90
+
91
+ #### OpenCode
92
+ ```
93
+ Read: lib/platform-templates/opencode.md
94
+ ```
95
+ Follow the template to generate:
96
+ - `.opencode/config.yaml` (main configuration)
97
+ - `.opencode/skills/` (one file per skill)
98
+ - `.opencode/rules/` (one file per rule)
99
+ - `.opencode/README.md` (brief explanation)
100
+
101
+ #### GitHub Copilot
102
+ ```
103
+ Read: lib/platform-templates/copilot.md
104
+ ```
105
+ Follow the template to generate:
106
+ - `.github/copilot-instructions.md` (single file, <8K tokens)
107
+
108
+ ### Step 6: Validate Generated Output
109
+
110
+ For each generated platform config:
111
+
112
+ - [ ] All skills from `.claude/skills/` are represented
113
+ - [ ] All rules from `.claude/rules/` are represented
114
+ - [ ] Project overview is included
115
+ - [ ] Platform-specific size limits are respected
116
+ - [ ] No Claude Code-specific tool references remain (Agent tool, model routing)
117
+ - [ ] File paths in generated content reference the correct platform directory
118
+
119
+ ### Step 7: Report Results
120
+
121
+ Display a summary:
122
+
123
+ ```
124
+ ═══════════════════════════════════════════════════════
125
+ Platform Config Generation Complete
126
+
127
+ Platform: {platform name(s)}
128
+ Skills translated: {N}
129
+ Rules translated: {N}
130
+
131
+ Files created:
132
+ {list each file created with path}
133
+
134
+ Source: .claude/ directory
135
+ Note: .claude/ remains the source of truth.
136
+ Re-run /init-platform after modifying skills or rules.
137
+
138
+ • "ок" — done
139
+ • "покажи {file}" — preview a generated file
140
+ • "перегенерируй {platform}" — regenerate for specific platform
141
+ ═══════════════════════════════════════════════════════
142
+ ```
143
+
144
+ ## Error Handling
145
+
146
+ | Error | Action |
147
+ |-------|--------|
148
+ | No `.claude/skills/` found | Abort with message: "No skills found in .claude/skills/. Nothing to translate." |
149
+ | No `.claude/rules/` found | Warn but continue: rules section will be empty |
150
+ | Template file missing | Abort with message: "Template not found: lib/platform-templates/{platform}.md" |
151
+ | Target file exists | See Step 4 (conflict resolution) |
152
+
153
+ ## Modular Reuse
154
+
155
+ This command follows the scan-then-generate pattern from `/brain-export`.
156
+ The template-based approach means adding a new platform requires only:
157
+ 1. A new template file in `lib/platform-templates/`
158
+ 2. An entry in `lib/platform-adapters.md`
159
+ 3. A new case in Step 5 of this command
160
+
161
+ No changes to the core command logic are needed for platform additions.
@@ -0,0 +1,130 @@
1
+ ---
2
+ description: "Show reward learning statistics: phase averages, domain patterns, skill effectiveness"
3
+ argument: "optional filters: --domain <name> --phase <number>"
4
+ ---
5
+
6
+ # Learning Stats -- Reward Analytics Dashboard
7
+
8
+ Display accumulated reward learning statistics from the Reward-Calibrated Learning System.
9
+
10
+ ## Protocol
11
+
12
+ Read `lib/reward-tracker.md` for the full analytics specification.
13
+
14
+ ### Step 1: Parse Arguments
15
+
16
+ Parse `$ARGUMENTS` for optional filters:
17
+ - `--domain <name>` -- Filter by domain (banking, retail, enterprise, healthcare)
18
+ - `--phase <number>` -- Filter by phase number (0-5)
19
+ - No arguments -- Show all data
20
+
21
+ ### Step 2: Check Memory Directory
22
+
23
+ Check if `.keysarium/memory/` exists and contains reward records.
24
+
25
+ If **no data exists**, display:
26
+ ```
27
+ ═══════════════════════════════════════════════════════
28
+ Learning Stats
29
+ ═══════════════════════════════════════════════════════
30
+
31
+ No reward data found in .keysarium/memory/
32
+
33
+ To start collecting data:
34
+ 1. Run a case with /casarium
35
+ 2. Respond at each checkpoint -- rewards are tracked automatically
36
+ 3. Run /learning-stats again after completing a case
37
+
38
+ Memory directory: .keysarium/memory/ (created on first pipeline run)
39
+ ═══════════════════════════════════════════════════════
40
+ ```
41
+
42
+ ### Step 3: Load and Compute Statistics
43
+
44
+ 1. Scan `.keysarium/memory/` recursively for all reward record JSON files.
45
+ 2. Exclude expired records (where `expires_at < current_date`).
46
+ 3. Apply filters from Step 1 (if provided).
47
+ 4. Compute statistics following the protocol in `lib/reward-tracker.md`:
48
+ - Per-phase reward averages with trend detection
49
+ - Per-domain breakdown with bottleneck identification
50
+ - Per-skill effectiveness rankings
51
+ - Domain pattern detection
52
+
53
+ ### Step 4: Write Updated Stats
54
+
55
+ Write computed statistics to:
56
+ - `.keysarium/memory/_stats/reward-summary.json`
57
+ - `.keysarium/memory/_patterns/domain-patterns.json`
58
+
59
+ ### Step 5: Display Results
60
+
61
+ Display formatted tables following the output format in `lib/reward-tracker.md`:
62
+
63
+ ```
64
+ ═══════════════════════════════════════════════════════
65
+ Learning Stats ({total_records} records, {total_cases} cases)
66
+ ═══════════════════════════════════════════════════════
67
+
68
+ Phase Reward Averages
69
+ ───────────────────────────────────────────
70
+ Phase | Avg | Runs | Trend |
71
+ ────────────|────────|──────|─────────────|
72
+ Phase 0 | {avg} | {n} | {trend} |
73
+ Phase 1 | {avg} | {n} | {trend} |
74
+ Phase 2 | {avg} | {n} | {trend} |
75
+ Phase 2.5 | {avg} | {n} | {trend} |
76
+ Phase 3 | {avg} | {n} | {trend} |
77
+ Phase 4 | {avg} | {n} | {trend} |
78
+ Phase 5 | {avg} | {n} | {trend} |
79
+ ────────────|────────|──────|─────────────|
80
+ Overall | {avg} | {n} | {trend} |
81
+
82
+ Domain Breakdown
83
+ ───────────────────────────────────────────
84
+ Domain | Avg | Cases | Bottleneck |
85
+ ────────────|────────|───────|─────────────|
86
+ {domain} | {avg} | {n} | {phase} |
87
+
88
+ Skill Effectiveness
89
+ ───────────────────────────────────────────
90
+ Skill | Avg | Best Domain |
91
+ ────────────────────────────|──────|─────────────|
92
+ {skill} | {avg}| {domain} |
93
+
94
+ Detected Patterns (confidence > 0.5)
95
+ ───────────────────────────────────────────
96
+ 1. [{confidence}] {description}
97
+ Advice: {actionable_advice}
98
+
99
+ ═══════════════════════════════════════════════════════
100
+
101
+ • "/learning-stats --domain banking" — filter by domain
102
+ • "/learning-stats --phase 2" — filter by phase
103
+ • "ок" — done
104
+ ═══════════════════════════════════════════════════════
105
+ ```
106
+
107
+ ### Step 6: Offer Actions
108
+
109
+ After displaying stats, offer:
110
+ - Filter by domain or phase (if not already filtered)
111
+ - "purge expired" -- Run retention policy cleanup
112
+ - "reset" -- Delete all memory data and start fresh (with confirmation)
113
+
114
+ ## Filtered Views
115
+
116
+ ### --domain Filter
117
+
118
+ When `--domain` is specified, show only:
119
+ - Phase averages for that domain
120
+ - Skill effectiveness in that domain
121
+ - Patterns for that domain
122
+ - Cases in that domain
123
+
124
+ ### --phase Filter
125
+
126
+ When `--phase` is specified, show only:
127
+ - That phase's statistics across all domains
128
+ - Domain breakdown for that specific phase
129
+ - Skills used in that phase with their rewards
130
+ - Patterns related to that phase
@@ -0,0 +1,140 @@
1
+ # /workers — Background Worker Management
2
+
3
+ Manage background workers for non-blocking operations in Keysarium.
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ /workers start <type> — Launch a background worker
9
+ /workers status — Show active workers and progress
10
+ /workers stop <id> — Stop a running worker
11
+ /workers list — List available worker types
12
+ ```
13
+
14
+ ## Arguments
15
+
16
+ $ARGUMENTS — Subcommand and optional parameters (e.g., "start consolidate", "status", "stop wkr-xxx", "list")
17
+
18
+ ## Protocol
19
+
20
+ ### Step 1: Parse Command
21
+
22
+ Parse $ARGUMENTS to determine the subcommand:
23
+
24
+ - If starts with "start": extract worker type from remaining args
25
+ - If "status": no additional args needed
26
+ - If starts with "stop": extract worker ID from remaining args
27
+ - If "list": no additional args needed
28
+ - If empty or unrecognized: show usage help
29
+
30
+ ### Step 2: Load Protocol
31
+
32
+ Read the worker protocol:
33
+ ```
34
+ Read: lib/background-workers.md
35
+ Read: .claude/rules/background-workers.md
36
+ ```
37
+
38
+ ### Step 3: Execute Subcommand
39
+
40
+ #### For `/workers list`
41
+
42
+ Display available worker types from the protocol:
43
+
44
+ ```
45
+ ═══════════════════════════════════════════════════════
46
+ Available Worker Types
47
+ ═══════════════════════════════════════════════════════
48
+
49
+ Type Model Description
50
+ consolidate sonnet Scan completed researches for patterns, update TOOLKIT_HARVEST.md
51
+ export-brain haiku Non-blocking brain export to .keysarium/exports/
52
+ health-check haiku Verify skill trust tiers, check for stale data
53
+ pattern-analysis sonnet Analyze reward data and trends across cases
54
+
55
+ Usage: /workers start <type>
56
+ ═══════════════════════════════════════════════════════
57
+ ```
58
+
59
+ #### For `/workers start <type>`
60
+
61
+ 1. Validate `<type>` is one of: consolidate, export-brain, health-check, pattern-analysis
62
+ 2. Ensure `.keysarium/workers/` directory exists (create if needed)
63
+ 3. Read or create `.keysarium/workers/registry.json`
64
+ 4. Count active workers (status = starting or running)
65
+ 5. If count >= 3: reject with "Maximum concurrent workers (3) reached"
66
+ 6. Generate worker ID: `wkr-{YYYYMMDD}-{HHmmss}-{type}`
67
+ 7. Create worker directory: `.keysarium/workers/{worker_id}/output/`
68
+ 8. Add entry to registry.json with status `starting`
69
+ 9. Read worker template from `lib/worker-templates/{type}.md`
70
+ 10. Spawn background agent:
71
+
72
+ ```
73
+ Use the Agent tool with:
74
+ - prompt: [Worker template content with WORKER_ID and OUTPUT_DIR injected]
75
+ - model: [From routing table in protocol]
76
+ - run_in_background: true
77
+ ```
78
+
79
+ 11. Report to user:
80
+ ```
81
+ Background worker started.
82
+ ID: {worker_id}
83
+ Type: {type}
84
+ Model: {model}
85
+ Output: .keysarium/workers/{worker_id}/
86
+
87
+ Use `/workers status` to check progress.
88
+ ```
89
+
90
+ #### For `/workers status`
91
+
92
+ 1. Read `.keysarium/workers/registry.json`
93
+ 2. If no registry or empty: "No workers have been started yet."
94
+ 3. For each worker in registry:
95
+ - Read `.keysarium/workers/{id}/status.json` if it exists
96
+ - Update registry entry with latest status
97
+ - If status.json missing and registry says "running": mark as "unknown"
98
+ 4. Prune entries older than 24 hours that are completed/failed/stopped
99
+ 5. Write updated registry
100
+ 6. Display formatted table:
101
+
102
+ ```
103
+ ═══════════════════════════════════════════════════════
104
+ Background Workers Status
105
+ ═══════════════════════════════════════════════════════
106
+
107
+ ID Type Status Progress Started
108
+ wkr-20260301-143022-consolidate consolidate running scanning (3/7) 14:30
109
+ wkr-20260301-143500-health-check health-check completed 6/6 checks 14:35
110
+ wkr-20260301-144000-export-brain export-brain failed — 14:40
111
+
112
+ Active: 1/3 | Completed: 1 | Failed: 1
113
+ ═══════════════════════════════════════════════════════
114
+ ```
115
+
116
+ If a worker is completed, also show output location:
117
+ ```
118
+ Completed worker output:
119
+ wkr-20260301-143500-health-check → .keysarium/workers/wkr-20260301-143500-health-check/output/
120
+ ```
121
+
122
+ #### For `/workers stop <id>`
123
+
124
+ 1. Read registry.json
125
+ 2. Find worker entry by ID (or prefix match for convenience)
126
+ 3. If not found: "Worker {id} not found in registry"
127
+ 4. If status is not `running`: "Worker {id} is not running (status: {status})"
128
+ 5. Write empty file: `.keysarium/workers/{id}/stop-requested`
129
+ 6. Update registry entry status to `stop-requested`
130
+ 7. Report:
131
+ ```
132
+ Stop requested for worker {id}.
133
+ Worker will stop at next safe point.
134
+ Use `/workers status` to confirm.
135
+ ```
136
+
137
+ ### Step 4: Confirm
138
+
139
+ After executing the subcommand, confirm the action was completed.
140
+ Do NOT display a checkpoint -- `/workers` is a utility command, not a pipeline phase.
@@ -0,0 +1,72 @@
1
+ # Background Workers Rules
2
+
3
+ ## When to Auto-Launch Workers
4
+
5
+ | Trigger | Worker Type | Condition |
6
+ |---------|------------|-----------|
7
+ | Case completion | `consolidate` | After 3rd completed `/casarium` case in project |
8
+ | Post-BTO test | `health-check` | After any `/bto-test` run (advisory, not enforced) |
9
+ | Manual | Any | User runs `/workers start <type>` |
10
+
11
+ Auto-launch triggers are ADVISORY. The system may suggest launching a worker but
12
+ MUST wait for user confirmation before actually spawning a background agent.
13
+
14
+ ## Worker Isolation Rules
15
+
16
+ 1. Workers MUST only write to `.keysarium/workers/{worker_id}/` directory
17
+ 2. Workers MUST NOT modify files in `researches/` (active research data)
18
+ 3. Workers MUST NOT modify files in `features/` (active feature data)
19
+ 4. Workers MUST NOT modify files in `.claude/` (commands, rules, skills)
20
+ 5. Workers MUST NOT modify `CLAUDE.md`, `TOOLKIT_HARVEST.md`, or any root-level file
21
+ 6. Workers MAY read any file in the project for analysis purposes
22
+ 7. Exception: `export-brain` worker MAY write to `.keysarium/exports/` (standard export location)
23
+
24
+ ## Model Routing for Workers
25
+
26
+ | Worker Type | Model | Rationale |
27
+ |-------------|-------|-----------|
28
+ | `consolidate` | sonnet | Pattern synthesis requires analytical reasoning |
29
+ | `export-brain` | haiku | Primarily file reading and JSON assembly |
30
+ | `health-check` | haiku | Structural checks, simple pattern matching |
31
+ | `pattern-analysis` | sonnet | Trend analysis requires deeper reasoning |
32
+
33
+ NEVER use opus for background workers -- workers perform routine tasks, not creative work.
34
+ ALWAYS specify the model parameter when spawning a worker agent.
35
+
36
+ ## Concurrency Limits
37
+
38
+ - Maximum concurrent workers: **3**
39
+ - If limit reached, new worker requests MUST be rejected (not queued)
40
+ - Rationale: prevent context exhaustion and ensure foreground responsiveness
41
+
42
+ ## Worker Naming Convention
43
+
44
+ When spawning worker agents, use this naming format:
45
+ ```
46
+ "Background Worker: {type} ({worker_id})"
47
+ ```
48
+
49
+ Example: `"Background Worker: consolidate (wkr-20260301-143022-consolidate)"`
50
+
51
+ ## Worker Timeout
52
+
53
+ - Workers are subject to the Agent tool's built-in timeout (~10 minutes)
54
+ - Design workers to complete within this window
55
+ - If a worker needs more time, it should checkpoint its progress and be re-launched
56
+
57
+ ## Registry Management
58
+
59
+ - Only the `/workers` command (orchestrator) may write to `registry.json`
60
+ - Workers write to their own `status.json` in their output directory
61
+ - This prevents write conflicts between the orchestrator and workers
62
+
63
+ ## Anti-Patterns
64
+
65
+ | Anti-Pattern | Detection | Fix |
66
+ |-------------|-----------|-----|
67
+ | Worker modifies research files | File write outside `.keysarium/workers/` | BLOCK -- enforce isolation |
68
+ | Worker uses opus model | Model parameter check | Use haiku or sonnet per routing table |
69
+ | More than 3 concurrent workers | Registry count check | Reject new worker start |
70
+ | Worker spawns sub-agents | Instruction check in template | Templates explicitly forbid sub-agents |
71
+ | Auto-launch without user consent | Missing user confirmation | Always ask before auto-launching |
72
+ | Worker runs indefinitely | No progress updates | Workers must update status.json periodically |
@@ -0,0 +1,90 @@
1
+ # Dream Cycles Integration Rules
2
+
3
+ ## Auto-Trigger Rules
4
+
5
+ When starting a new pipeline run (`/casarium` or `/feature-adr`), the orchestrator SHOULD check dream triggers:
6
+
7
+ 1. Read `.keysarium/insights/trigger-state.json`
8
+ 2. Evaluate triggers using the protocol in `lib/dream-engine.md`
9
+ 3. If any trigger is met, suggest to the user:
10
+ ```
11
+ Dream cycle trigger met ({reason}). Consider running /dream run for fresh insights.
12
+ ```
13
+ 4. This is ADVISORY only -- do not auto-launch without user confirmation
14
+ 5. If user declines, proceed normally
15
+
16
+ ### Trigger Check Timing
17
+
18
+ - Check triggers at pipeline START (before Phase 0 or Step 0)
19
+ - Do NOT check triggers mid-pipeline (would interrupt flow)
20
+ - Do NOT check triggers on simple commands (/harvest, /brain-export, /learning-stats)
21
+
22
+ ## Insight Application Rules
23
+
24
+ ### At /casarium Phase 0 (Discovery)
25
+
26
+ 1. After domain detection, check `.keysarium/insights/` for the most recent dream result
27
+ 2. Filter insights by detected domain
28
+ 3. For each relevant insight, apply:
29
+ - **Performance insights**: Adjust time budget recommendations for flagged phases
30
+ - **Effectiveness insights**: Note skill preferences in the case brief
31
+ - **Preference insights**: Flag preferred CJM variants for Phase 2.5
32
+ - **Anti-pattern insights**: Add explicit warnings to the case brief
33
+ 4. Log loaded insights: "Applied {count} dream insights for {domain} domain"
34
+
35
+ ### At /casarium Phase 2 (Research)
36
+
37
+ If a performance insight flags Phase 2 as problematic for the current domain:
38
+ - Log a warning: "Dream insight: Phase 2 is historically challenging for {domain}. Extra attention recommended."
39
+ - This is informational only -- does not change the research protocol
40
+
41
+ ### At /feature-adr Step 0 (Complexity Router)
42
+
43
+ Dream insights are NOT applied to feature-adr (different pipeline, different context).
44
+
45
+ ## Retention Rules
46
+
47
+ 1. Maximum 10 dream result files in `.keysarium/insights/`
48
+ 2. Retention is enforced at the END of each dream cycle (Step 5)
49
+ 3. Retention is also enforced by `/dream clear`
50
+ 4. `trigger-state.json` is NEVER deleted by retention (it is state, not a result)
51
+ 5. Dream result files are named `dream-{YYYYMMDD}-{HHmmss}.json` for chronological sorting
52
+
53
+ ## Integration with memory_store()
54
+
55
+ After writing a reward record via `memory_store()`, the system SHOULD:
56
+ 1. Attempt to read `.keysarium/insights/trigger-state.json`
57
+ 2. If it exists, increment `records_since_last_dream` and write back
58
+ 3. If it does not exist, skip silently (dream cycles not yet initialized)
59
+ 4. If write fails, log warning and continue (non-critical)
60
+
61
+ This integration is ADVISORY -- memory_store() must succeed even if trigger state update fails.
62
+
63
+ ## Integration with Event Triggers
64
+
65
+ ### Quality Gate Failure
66
+
67
+ When a BTO quality gate fails (Layer 0 rejection after 3 retries):
68
+ 1. Append event to `trigger-state.json`:
69
+ ```json
70
+ { "event_type": "quality_gate_failure", "timestamp": "...", "details": "BTO Layer 0 failed 3x" }
71
+ ```
72
+ 2. Suggest running `/dream run` to analyze the failure pattern
73
+
74
+ ### Case Completion
75
+
76
+ When a `/casarium` run completes (Phase 6 packaging done):
77
+ 1. Append event to `trigger-state.json`:
78
+ ```json
79
+ { "event_type": "case_completion", "timestamp": "...", "details": "Completed {slug}" }
80
+ ```
81
+ 2. If `records_since_last_dream >= 10` (half of volume threshold), suggest a dream run
82
+
83
+ ## Model Routing
84
+
85
+ | Operation | Model | Rationale |
86
+ |-----------|-------|-----------|
87
+ | Dream cycle execution | sonnet | Analytical pattern detection |
88
+ | Trigger evaluation | N/A | Deterministic JSON operations |
89
+ | Insight display | N/A | File reading and formatting |
90
+ | Status display | N/A | File reading and formatting |
@@ -0,0 +1,82 @@
1
+ # Feature ADR Conventions
2
+
3
+ ## When to Use /feature-adr vs Other Commands
4
+
5
+ | Situation | Command |
6
+ |-----------|---------|
7
+ | Implementing a software feature | `/feature-adr` |
8
+ | Researching an AI case for hackathon | `/casarium` |
9
+ | Solving a complex problem (no code) | `/solve` |
10
+ | Designing architecture only (no code) | `/architecture-phase` |
11
+ | Building a new skill/command | `/bto-build` |
12
+
13
+ ## Output Directory
14
+
15
+ All `/feature-adr` artifacts go into `features/<feature-slug>/`.
16
+ NEVER create feature artifacts in the project root or in `researches/`.
17
+
18
+ `researches/` is for `/casarium` pipeline only.
19
+ `features/` is for `/feature-adr` pipeline only.
20
+
21
+ ## Slug Naming
22
+
23
+ - Format: `kebab-case`, Latin characters only
24
+ - Max length: 40 characters
25
+ - Examples: `add-user-auth`, `refactor-payment-flow`, `migrate-to-postgres`
26
+ - NO dates, NO ticket numbers in slug (put those in the artifact files)
27
+
28
+ ## Artifact Naming
29
+
30
+ All artifacts use numbered prefix matching their step:
31
+
32
+ ```
33
+ 00_complexity_assessment.md
34
+ 01_requirements.md
35
+ 02_research.md
36
+ 03_adr/001-{decision-slug}.md
37
+ 04_domain_model.md
38
+ 05_architecture.md
39
+ 06_implementation_plan.md
40
+ 07_code_changes/change_manifest.md
41
+ 08_qe_report.md
42
+ ```
43
+
44
+ ## Complexity Tier Rules
45
+
46
+ - Tier is determined by Step 0 (Complexity Router) — never guess
47
+ - User can override tier at Checkpoint 0
48
+ - Once confirmed, tier determines which steps run
49
+ - Tier CANNOT change mid-pipeline (restart if scope changes significantly)
50
+
51
+ ## Integration with Existing Pipeline
52
+
53
+ `/feature-adr` is independent from the Casarium pipeline.
54
+ It does NOT use:
55
+ - Phase numbering (Phase 0-6)
56
+ - Research artifacts (00_product_discovery.md, etc.)
57
+ - CJM prototypes
58
+ - Presentation generation
59
+
60
+ It DOES share:
61
+ - Skills (`explore`, `problem-solver-enhanced`, `frontend-design`)
62
+ - Agent swarm patterns
63
+ - Checkpoint protocol
64
+ - Promise tag system
65
+ - Model routing rules
66
+
67
+ ## Feature Lifecycle
68
+
69
+ ```
70
+ /feature-adr [description]
71
+ → Step 0: classify
72
+ → Steps 1-5: design (per tier)
73
+ → Step 6: plan
74
+ → Step 7: code
75
+ → Step 8: QE
76
+ → Done: README.md + code changes in repo
77
+ ```
78
+
79
+ After completion:
80
+ - Code changes live in the actual codebase (not just in `features/`)
81
+ - `features/<slug>/` contains the design artifacts (ADRs, diagrams, reports)
82
+ - These artifacts serve as documentation for the feature