@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.
Files changed (47) hide show
  1. package/package.json +10 -2
  2. package/templates/.claude/commands/dream.md +101 -0
  3. package/templates/.claude/commands/feature-adr.md +92 -0
  4. package/templates/.claude/commands/init-platform.md +161 -0
  5. package/templates/.claude/commands/learning-stats.md +130 -0
  6. package/templates/.claude/commands/workers.md +140 -0
  7. package/templates/.claude/rules/background-workers.md +72 -0
  8. package/templates/.claude/rules/dream-cycles.md +90 -0
  9. package/templates/.claude/rules/feature-adr-conventions.md +82 -0
  10. package/templates/.claude/rules/reward-learning.md +124 -0
  11. package/templates/.claude/shards/feature-adr.shard.md +98 -0
  12. package/templates/.claude/skills/feature-adr/SKILL.md +252 -0
  13. package/templates/.claude/skills/feature-adr/examples/sample-feature-output.md +257 -0
  14. package/templates/.claude/skills/feature-adr/modules/00-complexity-router.md +114 -0
  15. package/templates/.claude/skills/feature-adr/modules/01-requirements.md +113 -0
  16. package/templates/.claude/skills/feature-adr/modules/02-research.md +92 -0
  17. package/templates/.claude/skills/feature-adr/modules/03-adr.md +135 -0
  18. package/templates/.claude/skills/feature-adr/modules/04-ddd.md +114 -0
  19. package/templates/.claude/skills/feature-adr/modules/05-architecture.md +149 -0
  20. package/templates/.claude/skills/feature-adr/modules/06-implementation-plan.md +129 -0
  21. package/templates/.claude/skills/feature-adr/modules/07-code.md +126 -0
  22. package/templates/.claude/skills/feature-adr/modules/08-qe.md +167 -0
  23. package/templates/.claude/skills/feature-adr/references/adr-template.md +102 -0
  24. package/templates/.claude/skills/feature-adr/references/c4-template.md +120 -0
  25. package/templates/.claude/skills/feature-adr/references/complexity-matrix.md +139 -0
  26. package/templates/.claude/skills/feature-adr/references/qe-checklist.md +86 -0
  27. package/templates/CLAUDE.md +124 -3
  28. package/templates/docs/improvement-directions.md +16 -16
  29. package/templates/docs/keysarium/01-deployment-guide.md +21 -12
  30. package/templates/docs/keysarium/02-admin-guide.md +204 -3
  31. package/templates/docs/keysarium/03-user-guide.md +224 -0
  32. package/templates/docs/keysarium/05-architecture.md +181 -0
  33. package/templates/docs/keysarium/06-user-flows.md +235 -0
  34. package/templates/lib/background-workers.md +278 -0
  35. package/templates/lib/dream-engine.md +460 -0
  36. package/templates/lib/judge-attestation.md +322 -0
  37. package/templates/lib/memory-protocol.md +239 -0
  38. package/templates/lib/platform-adapters.md +100 -0
  39. package/templates/lib/platform-templates/copilot.md +134 -0
  40. package/templates/lib/platform-templates/cursor.md +95 -0
  41. package/templates/lib/platform-templates/opencode.md +155 -0
  42. package/templates/lib/reward-tracker.md +256 -0
  43. package/templates/lib/witness-chain.md +372 -0
  44. package/templates/lib/worker-templates/brain-export.md +187 -0
  45. package/templates/lib/worker-templates/consolidate.md +180 -0
  46. package/templates/lib/worker-templates/dream-cycle.md +154 -0
  47. package/templates/lib/worker-templates/health-check.md +255 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dzhechkov/keysarium",
3
- "version": "1.1.2",
4
- "description": "AI Case Research Toolkit for Claude Code — full 7-phase pipeline for AI case studies, hackathons, and casariums",
3
+ "version": "1.2.0",
4
+ "description": "AI Case Research Toolkit for Claude Code — full 7-phase pipeline with feature-adr, dream cycles, background workers, multi-platform support, and reward learning",
5
5
  "main": "src/cli.js",
6
6
  "bin": {
7
7
  "keysarium": "./bin/cli.js"
@@ -39,5 +39,13 @@
39
39
  "homepage": "https://github.com/dzhechko/product-keysarium-2026#readme",
40
40
  "bugs": {
41
41
  "url": "https://github.com/dzhechko/product-keysarium-2026/issues"
42
+ },
43
+ "peerDependencies": {
44
+ "@dzhechkov/keysarium-core": "^1.0.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@dzhechkov/keysarium-core": {
48
+ "optional": true
49
+ }
42
50
  }
43
51
  }
@@ -0,0 +1,101 @@
1
+ # /dream -- Dream Cycles Management
2
+
3
+ Manage Dream Cycles: trigger dream analysis, view insights, check trigger status.
4
+
5
+ Dream Cycles build on the reward-calibrated learning system (`lib/memory-protocol.md`,
6
+ `lib/reward-tracker.md`) and background workers (`lib/background-workers.md`).
7
+
8
+ ## Usage
9
+
10
+ ```
11
+ /dream run — Manually trigger a dream cycle
12
+ /dream insights — Show latest insights
13
+ /dream status — Show trigger state
14
+ /dream clear — Clear old insights (keep last 10)
15
+ ```
16
+
17
+ The argument `$ARGUMENTS` determines which subcommand to execute.
18
+
19
+ ## Protocol
20
+
21
+ ### 1. Parse Subcommand
22
+
23
+ Parse `$ARGUMENTS` to determine subcommand:
24
+ - If starts with "run" -> execute RUN
25
+ - If starts with "insights" -> execute INSIGHTS
26
+ - If starts with "status" -> execute STATUS
27
+ - If starts with "clear" -> execute CLEAR
28
+ - If empty or unrecognized -> show usage help
29
+
30
+ ### 2. Execute Subcommand
31
+
32
+ #### RUN: Manually Trigger Dream Cycle
33
+
34
+ 1. Read the DreamEngine protocol: `lib/dream-engine.md`
35
+ 2. Read the worker template: `lib/worker-templates/dream-cycle.md`
36
+ 3. Read the background workers protocol: `lib/background-workers.md`
37
+ 4. Generate a worker ID: `wkr-{YYYYMMDD}-{HHmmss}-dream-cycle`
38
+ 5. Create worker directory: `.keysarium/workers/{worker_id}/output/`
39
+ 6. Register in `.keysarium/workers/registry.json`
40
+ 7. Launch background worker agent with:
41
+ - Prompt: Contents of `lib/worker-templates/dream-cycle.md` with WORKER_ID, OUTPUT_DIR, TRIGGER_REASON="manual" injected
42
+ - Model: sonnet
43
+ - run_in_background: true
44
+ 8. Report to user:
45
+
46
+ ```
47
+ Dream cycle started.
48
+ ID: {worker_id}
49
+ Trigger: manual
50
+ Model: sonnet
51
+ Output: .keysarium/workers/{worker_id}/
52
+
53
+ Use /dream status to check progress.
54
+ Use /dream insights to view results after completion.
55
+ ```
56
+
57
+ #### INSIGHTS: Show Latest Insights
58
+
59
+ 1. Check if `.keysarium/insights/` exists. If not, display empty state.
60
+ 2. List all `dream-*.json` files, sort by name DESC, take the first (most recent).
61
+ 3. Read the most recent dream result file.
62
+ 4. Display insights using the format from `lib/dream-engine.md` (Insight Display Format).
63
+ 5. Only show insights with `confidence >= 0.3`.
64
+ 6. If no dream files exist, display:
65
+
66
+ ```
67
+ No dream insights available yet.
68
+
69
+ To generate insights:
70
+ 1. Run several cases with /casarium (data is collected automatically)
71
+ 2. Run /dream run to trigger analysis
72
+ 3. Use /dream insights to view results
73
+
74
+ Dream insights are generated from accumulated reward data in .keysarium/memory/
75
+ ```
76
+
77
+ #### STATUS: Show Trigger State
78
+
79
+ 1. Read `.keysarium/insights/trigger-state.json`. If missing, display default state.
80
+ 2. Calculate time elapsed since `last_dream_completed_at`.
81
+ 3. Display using the format from `lib/dream-engine.md` (Status Display Format).
82
+ 4. Evaluate triggers and show which are met.
83
+ 5. If any trigger is met, suggest running `/dream run`.
84
+
85
+ #### CLEAR: Clear Old Insights
86
+
87
+ 1. List all `dream-*.json` files in `.keysarium/insights/`.
88
+ 2. Sort by name DESC.
89
+ 3. Keep the 10 most recent files.
90
+ 4. Delete older files.
91
+ 5. Report count of deleted files.
92
+ 6. If 10 or fewer files exist, report "Nothing to clear."
93
+
94
+ ```
95
+ Dream insights cleanup:
96
+ Total files: 15
97
+ Kept: 10 (most recent)
98
+ Deleted: 5
99
+
100
+ Trigger state preserved.
101
+ ```
@@ -0,0 +1,92 @@
1
+ # /feature-adr — Adaptive Feature Development Pipeline
2
+
3
+ ## Использование
4
+ ```
5
+ /feature-adr [описание фичи или путь к issue]
6
+ ```
7
+
8
+ ## Аргумент
9
+ $ARGUMENTS
10
+
11
+ ## Действия
12
+
13
+ 1. **Загрузи governance shard:** Прочитай `.claude/shards/feature-adr.shard.md`
14
+ 2. **Загрузи скилл:** Прочитай `.claude/skills/feature-adr/SKILL.md`
15
+
16
+ 3. **Step 0 — Complexity Router:**
17
+ - Прочитай `modules/00-complexity-router.md` и `references/complexity-matrix.md`
18
+ - Классифицируй фичу в S/M/L/XL
19
+ - Определи `{ACTIVE_STEPS}` и `{TIME_BUDGET}`
20
+ - Покажи Checkpoint 0 и **жди подтверждения tier**
21
+
22
+ 4. **Steps 1-8 — Execute Active Steps:**
23
+ - Для каждого шага из `{ACTIVE_STEPS}`:
24
+ - Прочитай `modules/{step}.md`
25
+ - Выполни протокол шага
26
+ - Создай артефакты в `features/<slug>/`
27
+ - Покажи Checkpoint N
28
+
29
+ 5. **Финализация:**
30
+ - Создай `features/<slug>/README.md` с summary
31
+ - Покажи итоговый отчёт
32
+
33
+ ## Создание директории
34
+
35
+ При первом запуске создай:
36
+ ```
37
+ features/<feature-slug>/
38
+ ├── diagrams/ ← для Mermaid диаграмм (M+)
39
+ ├── 03_adr/ ← для ADR файлов (M+)
40
+ └── 07_code_changes/ ← для манифеста изменений
41
+ ```
42
+
43
+ Slug: kebab-case из описания фичи (латиница, max 40 символов).
44
+
45
+ ## Параллелизация (Agent Swarm)
46
+
47
+ Для L/XL тiers:
48
+ - Steps 2+3 запускай параллельно (2 агента, sonnet + opus)
49
+ - Steps 4+5 можно параллельно если Step 3 уже завершён
50
+ - Step 7: N параллельных агентов (по одному на модуль)
51
+ - Step 8: 3 параллельных агента (unit ‖ integration ‖ review)
52
+
53
+ Для S/M: всё последовательно, параллелизация не нужна.
54
+
55
+ ## Model Routing
56
+
57
+ | Step | Model |
58
+ |------|-------|
59
+ | 0 Router | haiku |
60
+ | 1 Requirements | sonnet |
61
+ | 2 Research | sonnet |
62
+ | 3 ADR | opus |
63
+ | 4 DDD | opus |
64
+ | 5 Architecture | opus |
65
+ | 6 Impl Plan | sonnet |
66
+ | 7 Code | opus |
67
+ | 8 QE | sonnet |
68
+
69
+ ## Checkpoint формат
70
+
71
+ ```
72
+ ═══════════════════════════════════════════════════════
73
+ ⏸️ STEP N/8: [Step Name] Complete
74
+ <promise>[PROMISE_TAG]</promise>
75
+ Tier: {COMPLEXITY_TIER} | Active Steps: {ACTIVE_STEPS}
76
+
77
+ [Summary]
78
+ Artifacts: [list] ✅
79
+
80
+ • "ок" — next step
81
+ • "углуби [section]" — elaborate
82
+ • "[feedback]" — adjust
83
+ ═══════════════════════════════════════════════════════
84
+ ```
85
+
86
+ ## Critical Rules
87
+
88
+ - **НИКОГДА** не пропускай Step 0 (Router) — всегда классифицируй сначала
89
+ - **НИКОГДА** не начинай Step 7 (Code) без Step 6 (Plan)
90
+ - **НИКОГДА** не пропускай Step 8 (QE) — тестирование обязательно
91
+ - **ВСЕГДА** жди подтверждения пользователя на Checkpoint перед переходом
92
+ - **ВСЕ артефакты** создаются в `features/<slug>/`, не в корне проекта
@@ -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.