@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,278 @@
|
|
|
1
|
+
# Background Workers Protocol
|
|
2
|
+
|
|
3
|
+
> Core protocol for managing non-blocking background workers in Keysarium.
|
|
4
|
+
> Workers are Agent tool calls with `run_in_background: true` -- not OS-level daemons.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
Background workers enable long-running operations (pattern consolidation, brain export, health checks) to execute without blocking the foreground session. Each worker is an isolated Agent that reads its instructions from a template file and writes output to a dedicated directory.
|
|
9
|
+
|
|
10
|
+
## Worker Type Registry
|
|
11
|
+
|
|
12
|
+
| Type | Description | Model | Template |
|
|
13
|
+
|------|-------------|-------|----------|
|
|
14
|
+
| `consolidate` | Scan completed researches for patterns, update TOOLKIT_HARVEST.md | sonnet | `lib/worker-templates/consolidate.md` |
|
|
15
|
+
| `export-brain` | Non-blocking brain export to `.keysarium/exports/` | haiku | `lib/worker-templates/brain-export.md` |
|
|
16
|
+
| `health-check` | Verify skill trust tiers, check stale data, report system health | haiku | `lib/worker-templates/health-check.md` |
|
|
17
|
+
| `pattern-analysis` | Analyze reward data and trends across completed cases | sonnet | `lib/worker-templates/consolidate.md` (extended) |
|
|
18
|
+
|
|
19
|
+
## Directory Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
.keysarium/
|
|
23
|
+
└── workers/
|
|
24
|
+
├── registry.json ← Central registry (orchestrator-managed)
|
|
25
|
+
├── wkr-{YYYYMMDD}-{HHmmss}-{type}/ ← Per-worker directory
|
|
26
|
+
│ ├── status.json ← Worker-managed status
|
|
27
|
+
│ ├── stop-requested ← Flag file (orchestrator writes to request stop)
|
|
28
|
+
│ ├── output/ ← Worker output files
|
|
29
|
+
│ │ ├── patterns.json ← (consolidate)
|
|
30
|
+
│ │ ├── harvest-delta.md ← (consolidate)
|
|
31
|
+
│ │ ├── health-report.json ← (health-check)
|
|
32
|
+
│ │ └── brain-export-{timestamp}.json ← (export-brain)
|
|
33
|
+
│ └── error.log ← Written on failure
|
|
34
|
+
└── ...
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Worker ID Format
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
wkr-{YYYYMMDD}-{HHmmss}-{type}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Example: `wkr-20260301-143022-consolidate`
|
|
44
|
+
|
|
45
|
+
Generated by the orchestrator at launch time. Guaranteed unique within a day by including seconds.
|
|
46
|
+
|
|
47
|
+
## Registry Schema
|
|
48
|
+
|
|
49
|
+
The registry file (`.keysarium/workers/registry.json`) is managed ONLY by the orchestrator (`/workers` command). Workers NEVER modify this file.
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"version": "1.0",
|
|
54
|
+
"max_concurrent": 3,
|
|
55
|
+
"workers": [
|
|
56
|
+
{
|
|
57
|
+
"worker_id": "wkr-20260301-143022-consolidate",
|
|
58
|
+
"type": "consolidate",
|
|
59
|
+
"status": "running",
|
|
60
|
+
"model": "sonnet",
|
|
61
|
+
"started_at": "2026-03-01T14:30:22Z",
|
|
62
|
+
"completed_at": null,
|
|
63
|
+
"output_dir": ".keysarium/workers/wkr-20260301-143022-consolidate/",
|
|
64
|
+
"retry_count": 0
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Worker Status Schema
|
|
71
|
+
|
|
72
|
+
Each worker writes its own `status.json` to its output directory:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"worker_id": "wkr-20260301-143022-consolidate",
|
|
77
|
+
"type": "consolidate",
|
|
78
|
+
"status": "running",
|
|
79
|
+
"started_at": "2026-03-01T14:30:22Z",
|
|
80
|
+
"completed_at": null,
|
|
81
|
+
"progress": {
|
|
82
|
+
"phase": "scanning researches",
|
|
83
|
+
"items_processed": 3,
|
|
84
|
+
"total_items": 7
|
|
85
|
+
},
|
|
86
|
+
"error": null
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Status values: `starting`, `running`, `completing`, `completed`, `failed`, `stop-requested`, `stopped`
|
|
91
|
+
|
|
92
|
+
## Launch Protocol
|
|
93
|
+
|
|
94
|
+
When the orchestrator receives `/workers start <type>`:
|
|
95
|
+
|
|
96
|
+
### Step 1: Validate
|
|
97
|
+
|
|
98
|
+
1. Check that `<type>` is a valid worker type (see registry above)
|
|
99
|
+
2. Read `.keysarium/workers/registry.json` (create if not exists)
|
|
100
|
+
3. Count active workers (status = `starting` or `running`)
|
|
101
|
+
4. If count >= `max_concurrent` (default 3), reject with message:
|
|
102
|
+
```
|
|
103
|
+
Cannot start worker: maximum concurrent workers (3) reached.
|
|
104
|
+
Use `/workers status` to check active workers.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Step 2: Create Worker Directory
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
mkdir -p .keysarium/workers/wkr-{id}/output/
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Step 3: Update Registry
|
|
114
|
+
|
|
115
|
+
Add new entry to `registry.json` with status `starting`.
|
|
116
|
+
|
|
117
|
+
### Step 4: Load Template
|
|
118
|
+
|
|
119
|
+
Read the worker template from `lib/worker-templates/{type}.md`.
|
|
120
|
+
|
|
121
|
+
### Step 5: Spawn Agent
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
Use the Agent tool with these parameters:
|
|
125
|
+
- prompt: [Contents of worker template, with worker_id and output_dir injected]
|
|
126
|
+
- model: [From routing table: haiku or sonnet]
|
|
127
|
+
- run_in_background: true
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The agent prompt MUST include:
|
|
131
|
+
- The full worker template instructions
|
|
132
|
+
- The `worker_id` for status file naming
|
|
133
|
+
- The `output_dir` path for writing results
|
|
134
|
+
- Instructions to write `status.json` at start and completion
|
|
135
|
+
- Instructions to check for `stop-requested` file periodically
|
|
136
|
+
|
|
137
|
+
### Step 6: Confirm
|
|
138
|
+
|
|
139
|
+
Report to user:
|
|
140
|
+
```
|
|
141
|
+
Background worker started.
|
|
142
|
+
ID: wkr-20260301-143022-consolidate
|
|
143
|
+
Type: consolidate
|
|
144
|
+
Model: sonnet
|
|
145
|
+
Output: .keysarium/workers/wkr-20260301-143022-consolidate/
|
|
146
|
+
|
|
147
|
+
Use `/workers status` to check progress.
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Status Query Protocol
|
|
151
|
+
|
|
152
|
+
When the orchestrator receives `/workers status`:
|
|
153
|
+
|
|
154
|
+
1. Read `registry.json`
|
|
155
|
+
2. For each worker entry:
|
|
156
|
+
a. Read `.keysarium/workers/{id}/status.json`
|
|
157
|
+
b. Update registry entry with latest status from worker's file
|
|
158
|
+
3. Prune entries where `completed_at` is older than 24 hours
|
|
159
|
+
4. Write updated `registry.json`
|
|
160
|
+
5. Display formatted table:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
═══════════════════════════════════════════════════════
|
|
164
|
+
Background Workers Status
|
|
165
|
+
═══════════════════════════════════════════════════════
|
|
166
|
+
|
|
167
|
+
ID Type Status Progress Started
|
|
168
|
+
wkr-20260301-143022-consolidate consolidate running scanning (3/7) 14:30:22
|
|
169
|
+
wkr-20260301-143500-health-check health-check completed 6/6 checks 14:35:00
|
|
170
|
+
wkr-20260301-144000-export-brain export-brain completed — 14:40:00
|
|
171
|
+
|
|
172
|
+
Active: 1/3 | Completed: 2 | Failed: 0
|
|
173
|
+
═══════════════════════════════════════════════════════
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Stop Protocol
|
|
177
|
+
|
|
178
|
+
When the orchestrator receives `/workers stop <id>`:
|
|
179
|
+
|
|
180
|
+
1. Verify worker exists in registry and has status `running`
|
|
181
|
+
2. Write an empty file: `.keysarium/workers/{id}/stop-requested`
|
|
182
|
+
3. Update registry entry status to `stop-requested`
|
|
183
|
+
4. Report to user:
|
|
184
|
+
```
|
|
185
|
+
Stop requested for worker wkr-20260301-143022-consolidate.
|
|
186
|
+
Worker will stop at next safe point.
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The worker is responsible for:
|
|
190
|
+
- Checking for `stop-requested` file between major operations
|
|
191
|
+
- Writing final `status.json` with status `stopped`
|
|
192
|
+
- Exiting gracefully
|
|
193
|
+
|
|
194
|
+
If the worker does not stop within the Agent tool timeout (~10 minutes), it will terminate naturally.
|
|
195
|
+
|
|
196
|
+
## List Protocol
|
|
197
|
+
|
|
198
|
+
When the orchestrator receives `/workers list`:
|
|
199
|
+
|
|
200
|
+
Display available worker types:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
═══════════════════════════════════════════════════════
|
|
204
|
+
Available Worker Types
|
|
205
|
+
═══════════════════════════════════════════════════════
|
|
206
|
+
|
|
207
|
+
Type Model Description
|
|
208
|
+
consolidate sonnet Scan completed researches for patterns, update TOOLKIT_HARVEST.md
|
|
209
|
+
export-brain haiku Non-blocking brain export to .keysarium/exports/
|
|
210
|
+
health-check haiku Verify skill trust tiers, check for stale data
|
|
211
|
+
pattern-analysis sonnet Analyze reward data and trends across cases
|
|
212
|
+
|
|
213
|
+
Usage: /workers start <type>
|
|
214
|
+
═══════════════════════════════════════════════════════
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Error Handling
|
|
218
|
+
|
|
219
|
+
### Worker Failure
|
|
220
|
+
|
|
221
|
+
When a worker encounters an unrecoverable error:
|
|
222
|
+
|
|
223
|
+
1. Worker writes error details to `.keysarium/workers/{id}/error.log`
|
|
224
|
+
2. Worker writes `status.json` with status `failed` and error message
|
|
225
|
+
3. Agent completes (failure notification sent to foreground)
|
|
226
|
+
|
|
227
|
+
### Retry Logic
|
|
228
|
+
|
|
229
|
+
- Maximum 2 retries per original request
|
|
230
|
+
- Retry creates a NEW worker (new ID) with `retry_count` incremented
|
|
231
|
+
- If `retry_count >= 2`, mark as permanently failed
|
|
232
|
+
- User must manually re-launch if needed beyond 2 retries
|
|
233
|
+
|
|
234
|
+
### Registry Staleness
|
|
235
|
+
|
|
236
|
+
- On `/workers status`, entries older than 24 hours with status `completed`, `failed`, or `stopped` are pruned
|
|
237
|
+
- Entries with status `running` but no corresponding `status.json` are marked as `unknown`
|
|
238
|
+
|
|
239
|
+
## Model Routing Table
|
|
240
|
+
|
|
241
|
+
| Worker Type | Model | Rationale |
|
|
242
|
+
|-------------|-------|-----------|
|
|
243
|
+
| `consolidate` | sonnet | Pattern synthesis requires analytical reasoning |
|
|
244
|
+
| `export-brain` | haiku | Primarily file reading and JSON assembly |
|
|
245
|
+
| `health-check` | haiku | Structural checks, pattern matching |
|
|
246
|
+
| `pattern-analysis` | sonnet | Trend analysis requires deeper reasoning |
|
|
247
|
+
|
|
248
|
+
These mappings are enforced: the orchestrator MUST specify the correct model when spawning the Agent.
|
|
249
|
+
|
|
250
|
+
## Worker Isolation Rules
|
|
251
|
+
|
|
252
|
+
1. Workers MUST only write to their own `.keysarium/workers/{id}/` directory
|
|
253
|
+
2. Workers MUST NOT modify files in `researches/` directories
|
|
254
|
+
3. Workers MUST NOT modify files in `features/` directories
|
|
255
|
+
4. Workers MUST NOT modify `CLAUDE.md` or any file in `.claude/`
|
|
256
|
+
5. The `consolidate` worker MAY read `TOOLKIT_HARVEST.md` but writes updates to `output/harvest-delta.md` (the user decides whether to apply)
|
|
257
|
+
6. Workers MUST NOT spawn sub-agents
|
|
258
|
+
|
|
259
|
+
## Integration with Existing Commands
|
|
260
|
+
|
|
261
|
+
### /harvest Integration
|
|
262
|
+
|
|
263
|
+
The `consolidate` worker extends `/harvest` with background execution:
|
|
264
|
+
- `/harvest` = foreground, interactive, with user confirmation
|
|
265
|
+
- `/workers start consolidate` = background, non-interactive, writes delta for review
|
|
266
|
+
|
|
267
|
+
### /brain-export Integration
|
|
268
|
+
|
|
269
|
+
The `export-brain` worker provides a non-blocking alternative:
|
|
270
|
+
- `/brain-export` = foreground, with progress display
|
|
271
|
+
- `/workers start export-brain` = background, writes to `.keysarium/exports/`
|
|
272
|
+
|
|
273
|
+
### Auto-launch Triggers (Future)
|
|
274
|
+
|
|
275
|
+
Workers can be auto-launched based on triggers:
|
|
276
|
+
- After 3rd completed `/casarium` case: auto-launch `consolidate`
|
|
277
|
+
- After any `/bto-test` run: auto-launch `health-check`
|
|
278
|
+
- These triggers are advisory and can be disabled in rules
|