@dzhechkov/keysarium-core 1.0.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 +126 -0
- package/governance/checkpoint-protocol.md +129 -0
- package/governance/constitution.md +144 -0
- package/governance/shard-protocol.md +118 -0
- package/index.md +89 -0
- package/memory/dream-engine.md +148 -0
- package/memory/memory-protocol.md +197 -0
- package/memory/reward-tracker.md +162 -0
- package/orchestration/background-workers.md +141 -0
- package/orchestration/model-routing.md +92 -0
- package/orchestration/queen-protocol.md +154 -0
- package/orchestration/topology-selection.md +175 -0
- package/package.json +44 -0
- package/platform/adapter-registry.md +93 -0
- package/platform/templates/copilot.md +81 -0
- package/platform/templates/cursor.md +65 -0
- package/platform/templates/opencode.md +69 -0
- package/trust-tiers/promotion-protocol.md +144 -0
- package/trust-tiers/tier-system.md +111 -0
- package/verification/audit-trail.md +154 -0
- package/verification/judge-attestation.md +130 -0
- package/verification/witness-chain.md +138 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @dzhechkov/keysarium-core
|
|
2
|
+
|
|
3
|
+
Core framework for building multi-agent pipelines with governance, memory, orchestration, verification, and trust tier systems.
|
|
4
|
+
|
|
5
|
+
## What is keysarium-core?
|
|
6
|
+
|
|
7
|
+
keysarium-core provides **domain-agnostic protocols** for any AI-powered multi-agent pipeline. It defines how agents coordinate, how decisions are verified, how the system learns from past executions, and how governance rules are enforced.
|
|
8
|
+
|
|
9
|
+
Think of it as the "operating system" for multi-agent workflows. You bring the domain-specific skills and pipeline stages; keysarium-core provides the infrastructure.
|
|
10
|
+
|
|
11
|
+
## Modules
|
|
12
|
+
|
|
13
|
+
| Module | Purpose | Key Protocols |
|
|
14
|
+
|--------|---------|---------------|
|
|
15
|
+
| **governance/** | Structural rules and human checkpoints | Constitution, shard protocol, promise tags |
|
|
16
|
+
| **memory/** | Persistent learning across executions | memory_query, memory_store, reward tracking, dream cycles |
|
|
17
|
+
| **orchestration/** | Agent coordination and model routing | Queen protocol, 6 topologies, background workers, 3-tier routing |
|
|
18
|
+
| **verification/** | Cryptographic integrity and isolation proofs | SHA-256 witness chain, judge attestation, audit trail |
|
|
19
|
+
| **trust-tiers/** | Skill/artifact quality classification | 4-tier system (Advisory to Verified), promotion protocol |
|
|
20
|
+
| **platform/** | Multi-platform config generation | Cursor, OpenCode, GitHub Copilot adapters |
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @dzhechkov/keysarium-core
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Using with an Existing Pipeline
|
|
31
|
+
|
|
32
|
+
keysarium-core protocols are markdown-based. They define algorithms, schemas, and rules that AI agents read and follow. To integrate:
|
|
33
|
+
|
|
34
|
+
1. **Governance:** Read `governance/constitution.md` at pipeline start to load invariants
|
|
35
|
+
2. **Memory:** Call `memory_query()` before each stage, `memory_store()` after each checkpoint
|
|
36
|
+
3. **Orchestration:** Select topology per stage from `orchestration/topology-selection.md`
|
|
37
|
+
4. **Verification:** Create witness chain records at each stage completion
|
|
38
|
+
5. **Trust Tiers:** Classify your skills using `trust-tiers/tier-system.md`
|
|
39
|
+
|
|
40
|
+
### Using with Keysarium Research Pipeline
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @dzhechkov/keysarium @dzhechkov/keysarium-core
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using with BTO Evaluation Pipeline
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @dzhechkov/skills-bto @dzhechkov/keysarium-core
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Architecture
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
@dzhechkov/keysarium-core <-- You are here
|
|
56
|
+
^ ^
|
|
57
|
+
| |
|
|
58
|
+
peerDep peerDep
|
|
59
|
+
| |
|
|
60
|
+
@dzhechkov/keysarium @dzhechkov/skills-bto
|
|
61
|
+
(research) (evaluation)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
keysarium-core has **zero dependencies** on either consumer package. Both consumers declare keysarium-core as a peer dependency. Any team can use keysarium-core independently to build their own pipeline.
|
|
65
|
+
|
|
66
|
+
## Module Reference
|
|
67
|
+
|
|
68
|
+
### Governance
|
|
69
|
+
|
|
70
|
+
- `constitution.md` — Universal invariants that must never be violated
|
|
71
|
+
- `shard-protocol.md` — How to create per-stage governance rules that are reloaded at each stage to prevent context drift
|
|
72
|
+
- `checkpoint-protocol.md` — Human synchronization points with promise tags for machine-readable completion signals
|
|
73
|
+
|
|
74
|
+
### Memory
|
|
75
|
+
|
|
76
|
+
- `memory-protocol.md` — Core `memory_query()` / `memory_store()` protocol for loading and persisting execution patterns with reward scores
|
|
77
|
+
- `reward-tracker.md` — Analytics engine: per-stage averages, per-domain breakdowns, bottleneck detection, trend analysis
|
|
78
|
+
- `dream-engine.md` — Background consolidation: builds concept graphs from accumulated data and generates cross-domain insights
|
|
79
|
+
|
|
80
|
+
### Orchestration
|
|
81
|
+
|
|
82
|
+
- `queen-protocol.md` — 10-step coordinator lifecycle: init, health, load, detect, shard, orchestrate, monitor, collect, store, report
|
|
83
|
+
- `topology-selection.md` — 6 agent arrangement patterns: star, mesh, hierarchical, ring, hybrid, adaptive
|
|
84
|
+
- `background-workers.md` — Non-blocking worker protocol: launch, status, stop, error handling, isolation rules
|
|
85
|
+
- `model-routing.md` — 3-tier model assignment: haiku (fast/cheap), sonnet (balanced), opus (creative/complex)
|
|
86
|
+
|
|
87
|
+
### Verification
|
|
88
|
+
|
|
89
|
+
- `witness-chain.md` — SHA-256 hash-chain protocol for tamper-evident artifact integrity
|
|
90
|
+
- `judge-attestation.md` — Cryptographic proof that evaluators operated independently
|
|
91
|
+
- `audit-trail.md` — Complete evaluation history format with chain integrity verification
|
|
92
|
+
|
|
93
|
+
### Trust Tiers
|
|
94
|
+
|
|
95
|
+
- `tier-system.md` — 4-tier classification: Tier 0 (Advisory), Tier 1 (Structured), Tier 2 (Validated), Tier 3 (Verified)
|
|
96
|
+
- `promotion-protocol.md` — How to promote skills between tiers based on evaluation evidence
|
|
97
|
+
|
|
98
|
+
### Platform
|
|
99
|
+
|
|
100
|
+
- `adapter-registry.md` — Central registry of supported AI coding platforms
|
|
101
|
+
- `templates/cursor.md` — Cursor (.cursorrules) generation template
|
|
102
|
+
- `templates/opencode.md` — OpenCode (.opencode/) generation template
|
|
103
|
+
- `templates/copilot.md` — GitHub Copilot (.github/copilot-instructions.md) generation template
|
|
104
|
+
|
|
105
|
+
## Building Your Own Pipeline
|
|
106
|
+
|
|
107
|
+
To create a custom multi-agent pipeline using keysarium-core:
|
|
108
|
+
|
|
109
|
+
1. Define your stages (equivalent to Keysarium's phases or BTO's layers)
|
|
110
|
+
2. Create governance shards for each stage using `governance/shard-protocol.md`
|
|
111
|
+
3. Choose topologies per stage using `orchestration/topology-selection.md`
|
|
112
|
+
4. Configure model routing using `orchestration/model-routing.md`
|
|
113
|
+
5. Implement witness chain at stage boundaries using `verification/witness-chain.md`
|
|
114
|
+
6. Enable learning with `memory/memory-protocol.md`
|
|
115
|
+
|
|
116
|
+
## Origins
|
|
117
|
+
|
|
118
|
+
keysarium-core was extracted from the [Keysarium](https://github.com/dzhechko/product-keysarium-2026) project, which implements a 7-phase AI research pipeline. The protocols are inspired by:
|
|
119
|
+
|
|
120
|
+
- **Ruflo** — 7-layer governance, 6 topologies, 3-tier model routing
|
|
121
|
+
- **Agentic QE** — Trust tiers, reward-calibrated learning, dream cycles, PACT principles
|
|
122
|
+
- **Quality Forge** — Portable brain containers, SHA-256 witness chains
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Checkpoint Protocol — Human Synchronization Points
|
|
2
|
+
|
|
3
|
+
> Universal protocol for checkpoints and semantic completion promises in multi-agent pipelines.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A checkpoint is a mandatory pause point where the pipeline stops and waits for human confirmation before proceeding. Checkpoints serve three purposes:
|
|
8
|
+
|
|
9
|
+
1. **Quality gate** — Human reviews the stage output before the next stage begins
|
|
10
|
+
2. **Feedback loop** — Human provides corrections or approvals that calibrate the system
|
|
11
|
+
3. **Completion signal** — A machine-readable promise tag records that the stage is done
|
|
12
|
+
|
|
13
|
+
## Checkpoint Format
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
=====================================================
|
|
17
|
+
CHECKPOINT {N}: {Stage Name} Complete
|
|
18
|
+
<promise>{PROMISE_TAG}</promise>
|
|
19
|
+
|
|
20
|
+
{2-3 line summary of what was accomplished}
|
|
21
|
+
Artifacts created: {list of files}
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
- "ok" / "proceed" — advance to next stage
|
|
25
|
+
- "deepen {section}" — elaborate on a specific section
|
|
26
|
+
- "{specific feedback}" — adjust current stage output
|
|
27
|
+
=====================================================
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Semantic Completion Promises
|
|
31
|
+
|
|
32
|
+
### What is a Promise?
|
|
33
|
+
|
|
34
|
+
A promise is a machine-readable tag embedded in the checkpoint output that signals the stage's completion status. It follows the format:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
<promise>{TAG_NAME}</promise>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Promise Rules
|
|
41
|
+
|
|
42
|
+
1. A promise tag MUST only be emitted AFTER its conditions are verifiably met
|
|
43
|
+
2. If conditions are NOT met, emit `<promise>{TAG_NAME}_INCOMPLETE</promise>` instead
|
|
44
|
+
3. Downstream stages SHOULD check for upstream promises before starting
|
|
45
|
+
4. Promise tags replace informal "stage done" signals with formal, parseable markers
|
|
46
|
+
|
|
47
|
+
### Defining Promises for Your Pipeline
|
|
48
|
+
|
|
49
|
+
Each stage in your pipeline should define:
|
|
50
|
+
|
|
51
|
+
| Stage | Promise Tag | Conditions |
|
|
52
|
+
|-------|-------------|------------|
|
|
53
|
+
| Stage 0 | `{PIPELINE}_STAGE_0_COMPLETE` | All stage 0 artifacts created and validated |
|
|
54
|
+
| Stage 1 | `{PIPELINE}_STAGE_1_COMPLETE` | All stage 1 artifacts created and validated |
|
|
55
|
+
| ... | ... | ... |
|
|
56
|
+
|
|
57
|
+
Replace `{PIPELINE}` with your pipeline's name (e.g., `RESEARCH`, `BTO`, `QE`).
|
|
58
|
+
|
|
59
|
+
### Promise Validation
|
|
60
|
+
|
|
61
|
+
At each stage start, the orchestrator should verify upstream promises:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
1. Read the checkpoint history
|
|
65
|
+
2. Check that all required upstream promises exist
|
|
66
|
+
3. If any promise is missing or has _INCOMPLETE suffix:
|
|
67
|
+
a. Log: "Missing prerequisite: {TAG_NAME}"
|
|
68
|
+
b. Do NOT proceed — return to the incomplete stage
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Checkpoint Behavior
|
|
72
|
+
|
|
73
|
+
### On "ok" Response
|
|
74
|
+
|
|
75
|
+
1. Store the reward (1.0 — excellent) via memory_store
|
|
76
|
+
2. Emit the stage's promise tag
|
|
77
|
+
3. Advance to the next stage
|
|
78
|
+
|
|
79
|
+
### On Feedback Response
|
|
80
|
+
|
|
81
|
+
1. Parse feedback to determine scope
|
|
82
|
+
2. If minor (one section): store reward 0.7, adjust, re-checkpoint
|
|
83
|
+
3. If major (multiple sections): store reward 0.3, rework, re-checkpoint
|
|
84
|
+
4. If restart requested: store reward 0.0, restart stage from scratch
|
|
85
|
+
|
|
86
|
+
### On No Response
|
|
87
|
+
|
|
88
|
+
If the session ends without a response at the checkpoint:
|
|
89
|
+
- Do NOT store any reward (no record created)
|
|
90
|
+
- Do NOT emit any promise tag
|
|
91
|
+
- The stage remains in an indeterminate state
|
|
92
|
+
|
|
93
|
+
## Checkpoint Timing
|
|
94
|
+
|
|
95
|
+
Each checkpoint should display time spent vs. budget:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
Time: {minutes_spent}m / {budget}m ({percentage}%)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
If a stage exceeds its time budget, the checkpoint should include a warning:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Warning: Time budget exceeded ({percentage}% used). Consider wrapping up.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Integration with Governance
|
|
108
|
+
|
|
109
|
+
Checkpoints are the primary enforcement point for governance rules:
|
|
110
|
+
|
|
111
|
+
1. Before displaying the checkpoint, run all constitution invariant checks
|
|
112
|
+
2. Before displaying the checkpoint, validate all quality gates from the stage's shard
|
|
113
|
+
3. If any gate fails, indicate it in the checkpoint and require the human to acknowledge
|
|
114
|
+
|
|
115
|
+
## Integration with Memory
|
|
116
|
+
|
|
117
|
+
After each checkpoint response:
|
|
118
|
+
|
|
119
|
+
1. Determine the reward score based on the human's response type
|
|
120
|
+
2. Call `memory_store()` with the stage context and reward
|
|
121
|
+
3. This enables the system to learn which stages perform well and which need improvement
|
|
122
|
+
|
|
123
|
+
## Integration with Witness Chain
|
|
124
|
+
|
|
125
|
+
After each checkpoint with "ok" response:
|
|
126
|
+
|
|
127
|
+
1. Compute the SHA-256 hash of the stage's primary artifact
|
|
128
|
+
2. Append a record to the witness chain
|
|
129
|
+
3. The promise tag is recorded in the chain record
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Constitution — Universal Invariants
|
|
2
|
+
|
|
3
|
+
> Unbreakable rules for any multi-agent pipeline. These invariants are enforced at every stage gate and may never be violated.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A Constitution defines the set of rules that are **always true** regardless of pipeline configuration, domain, or stage. They serve as hard enforcement gates — if an invariant is violated, the pipeline must halt.
|
|
8
|
+
|
|
9
|
+
This is inspired by the 7-layer governance model (Ruflo) and the 7 constitutional invariants (Agentic QE).
|
|
10
|
+
|
|
11
|
+
## Defining Invariants
|
|
12
|
+
|
|
13
|
+
Each invariant follows this format:
|
|
14
|
+
|
|
15
|
+
```markdown
|
|
16
|
+
### INV-{NNN}: {Short Name}
|
|
17
|
+
|
|
18
|
+
**Rule:** {One-sentence statement of what must always be true}
|
|
19
|
+
|
|
20
|
+
**Enforcement:** {How to check — deterministic check, file existence, hash verification, etc.}
|
|
21
|
+
|
|
22
|
+
**On violation:** {HALT | WARN | RETRY(N)}
|
|
23
|
+
|
|
24
|
+
**Rationale:** {Why this invariant exists}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Template Invariants
|
|
28
|
+
|
|
29
|
+
The following invariants are recommended as a starting point for any multi-agent pipeline. Customize or extend based on your domain.
|
|
30
|
+
|
|
31
|
+
### INV-001: Artifact Integrity
|
|
32
|
+
|
|
33
|
+
**Rule:** Every artifact produced by a stage must be verifiable against its witness chain hash.
|
|
34
|
+
|
|
35
|
+
**Enforcement:** After each stage completion, verify that the artifact file exists and its SHA-256 hash matches the chain record.
|
|
36
|
+
|
|
37
|
+
**On violation:** HALT — artifact may have been tampered with.
|
|
38
|
+
|
|
39
|
+
**Rationale:** Ensures no artifact is silently modified between stages.
|
|
40
|
+
|
|
41
|
+
### INV-002: Stage Completion Signal
|
|
42
|
+
|
|
43
|
+
**Rule:** A stage may not be marked complete without emitting a promise tag.
|
|
44
|
+
|
|
45
|
+
**Enforcement:** Check that the stage's checkpoint includes a `<promise>` tag matching the expected value.
|
|
46
|
+
|
|
47
|
+
**On violation:** HALT — downstream stages cannot trust upstream completion.
|
|
48
|
+
|
|
49
|
+
**Rationale:** Promise tags are machine-readable signals that formalize stage gates.
|
|
50
|
+
|
|
51
|
+
### INV-003: Human Checkpoint Required
|
|
52
|
+
|
|
53
|
+
**Rule:** A stage may not auto-advance to the next stage without human confirmation at the checkpoint.
|
|
54
|
+
|
|
55
|
+
**Enforcement:** The orchestrator must wait for explicit user input before proceeding.
|
|
56
|
+
|
|
57
|
+
**On violation:** HALT — no auto-advancement permitted.
|
|
58
|
+
|
|
59
|
+
**Rationale:** Human-in-the-loop prevents runaway automation and ensures quality.
|
|
60
|
+
|
|
61
|
+
### INV-004: Evaluator Independence
|
|
62
|
+
|
|
63
|
+
**Rule:** Evaluators (judges) in a multi-evaluator panel must operate in strict isolation. No evaluator may see another evaluator's score before submitting its own.
|
|
64
|
+
|
|
65
|
+
**Enforcement:** Judge attestation protocol — each judge creates a hash of its evaluation before scores are shared.
|
|
66
|
+
|
|
67
|
+
**On violation:** HALT — evaluation integrity compromised.
|
|
68
|
+
|
|
69
|
+
**Rationale:** Independent evaluation prevents conformity collapse and produces more reliable quality signals.
|
|
70
|
+
|
|
71
|
+
### INV-005: Loop Detection
|
|
72
|
+
|
|
73
|
+
**Rule:** No agent may perform the same action more than 3 consecutive times without variation.
|
|
74
|
+
|
|
75
|
+
**Enforcement:** Track the last 3 actions per agent. If identical, halt and escalate.
|
|
76
|
+
|
|
77
|
+
**On violation:** WARN + escalate to coordinator.
|
|
78
|
+
|
|
79
|
+
**Rationale:** Prevents infinite loops and wasted resources.
|
|
80
|
+
|
|
81
|
+
### INV-006: Memory Consistency
|
|
82
|
+
|
|
83
|
+
**Rule:** No contradictory patterns may coexist in the memory system.
|
|
84
|
+
|
|
85
|
+
**Enforcement:** When storing a new pattern, check for existing patterns with the same pattern_id but conflicting content. If found, the newer pattern supersedes the older.
|
|
86
|
+
|
|
87
|
+
**On violation:** WARN — resolve by keeping the most recent pattern.
|
|
88
|
+
|
|
89
|
+
**Rationale:** Contradictory patterns degrade learning quality.
|
|
90
|
+
|
|
91
|
+
### INV-007: No Unverified Claims
|
|
92
|
+
|
|
93
|
+
**Rule:** Research outputs must not contain unverified factual claims presented as verified.
|
|
94
|
+
|
|
95
|
+
**Enforcement:** Scan output artifacts for factual claims. Each must have a source citation or be marked as `[ANALYSIS]` or `[UNVERIFIED]`.
|
|
96
|
+
|
|
97
|
+
**On violation:** HALT — return to research stage for verification.
|
|
98
|
+
|
|
99
|
+
**Rationale:** Unverified claims undermine the credibility of the entire pipeline output.
|
|
100
|
+
|
|
101
|
+
## Customization
|
|
102
|
+
|
|
103
|
+
### Adding Domain-Specific Invariants
|
|
104
|
+
|
|
105
|
+
To add invariants for your pipeline:
|
|
106
|
+
|
|
107
|
+
1. Create a file `governance/constitution-{domain}.md` with additional invariants
|
|
108
|
+
2. Number new invariants starting from INV-100 (to avoid conflicts with core)
|
|
109
|
+
3. Follow the same format (Rule, Enforcement, On violation, Rationale)
|
|
110
|
+
|
|
111
|
+
### Example: Banking Domain
|
|
112
|
+
|
|
113
|
+
```markdown
|
|
114
|
+
### INV-100: Data Perimeter
|
|
115
|
+
|
|
116
|
+
**Rule:** No customer data may leave the security perimeter.
|
|
117
|
+
|
|
118
|
+
**Enforcement:** All LLM calls must be to on-premise models (no external API calls).
|
|
119
|
+
|
|
120
|
+
**On violation:** HALT — regulatory breach (FZ-152).
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Example: Evaluation Domain (BTO)
|
|
124
|
+
|
|
125
|
+
```markdown
|
|
126
|
+
### INV-100: Judge-Generator Separation
|
|
127
|
+
|
|
128
|
+
**Rule:** The model used for generating an artifact must differ from the model used for evaluating it.
|
|
129
|
+
|
|
130
|
+
**Enforcement:** Compare model IDs at evaluation start.
|
|
131
|
+
|
|
132
|
+
**On violation:** HALT — self-evaluation bias.
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Enforcement Integration
|
|
136
|
+
|
|
137
|
+
At each stage gate (checkpoint), the orchestrator should:
|
|
138
|
+
|
|
139
|
+
1. Load the constitution (this file)
|
|
140
|
+
2. Load any domain-specific constitution extensions
|
|
141
|
+
3. Run each invariant's enforcement check
|
|
142
|
+
4. If any check fails with HALT severity, stop the pipeline
|
|
143
|
+
5. If any check fails with WARN severity, log and continue
|
|
144
|
+
6. If any check fails with RETRY severity, retry up to N times before halting
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Shard Protocol — Per-Stage Governance Rules
|
|
2
|
+
|
|
3
|
+
> How to create and load governance shards that prevent context drift during long sessions.
|
|
4
|
+
|
|
5
|
+
## Problem
|
|
6
|
+
|
|
7
|
+
In long-running multi-agent sessions, rules loaded at the beginning drift out of the agent's active context after approximately 40 minutes. By the time later stages execute, the agent may have "forgotten" critical rules.
|
|
8
|
+
|
|
9
|
+
## Solution
|
|
10
|
+
|
|
11
|
+
Each pipeline stage gets its own **governance shard** — a focused set of rules that is re-read at the start of that stage. This ensures the agent always has the relevant rules in active context.
|
|
12
|
+
|
|
13
|
+
## Shard Format
|
|
14
|
+
|
|
15
|
+
Each shard is a markdown file with the following structure:
|
|
16
|
+
|
|
17
|
+
```markdown
|
|
18
|
+
# {Stage Name} Governance Shard
|
|
19
|
+
|
|
20
|
+
## Time Budget
|
|
21
|
+
- Allocated: {percentage}% of total pipeline time
|
|
22
|
+
- Hard limit: {minutes} minutes
|
|
23
|
+
|
|
24
|
+
## Prerequisites
|
|
25
|
+
- Required upstream promises: [{PROMISE_TAG_1}, {PROMISE_TAG_2}]
|
|
26
|
+
- Required input files: [{file_list}]
|
|
27
|
+
|
|
28
|
+
## Skill to Load
|
|
29
|
+
- Primary: {skill_name} (read SKILL.md at: {path})
|
|
30
|
+
- Secondary: {skill_name} (optional)
|
|
31
|
+
|
|
32
|
+
## Rules for This Stage
|
|
33
|
+
1. {Rule 1 — specific to this stage}
|
|
34
|
+
2. {Rule 2}
|
|
35
|
+
3. ...
|
|
36
|
+
|
|
37
|
+
## Quality Gates
|
|
38
|
+
- [ ] {Gate 1 — what must be true for this stage to pass}
|
|
39
|
+
- [ ] {Gate 2}
|
|
40
|
+
- [ ] {Gate 3}
|
|
41
|
+
|
|
42
|
+
## Promise Tag
|
|
43
|
+
On successful completion, emit: `<promise>{PROMISE_TAG}</promise>`
|
|
44
|
+
|
|
45
|
+
## Anti-Patterns for This Stage
|
|
46
|
+
| Pattern | Fix |
|
|
47
|
+
|---------|-----|
|
|
48
|
+
| {Anti-pattern 1} | {Fix} |
|
|
49
|
+
| {Anti-pattern 2} | {Fix} |
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Shard Naming Convention
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
{stage-id}.shard.md
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Examples:
|
|
59
|
+
- `stage-0-init.shard.md`
|
|
60
|
+
- `stage-1-analysis.shard.md`
|
|
61
|
+
- `stage-2-research.shard.md`
|
|
62
|
+
- `bto-evaluation.shard.md`
|
|
63
|
+
|
|
64
|
+
## Shard Loading Protocol
|
|
65
|
+
|
|
66
|
+
At the start of each stage:
|
|
67
|
+
|
|
68
|
+
1. **Determine shard path:** Construct the shard filename from the stage ID
|
|
69
|
+
2. **Read shard:** Load the shard file content into the agent's context
|
|
70
|
+
3. **Validate prerequisites:** Check that all required upstream promises have been emitted
|
|
71
|
+
4. **Validate inputs:** Check that all required input files exist
|
|
72
|
+
5. **Load skill:** If the shard specifies a skill, read its SKILL.md
|
|
73
|
+
6. **Start timer:** Begin tracking time against the shard's budget
|
|
74
|
+
7. **Execute stage:** Follow the shard's rules and quality gates
|
|
75
|
+
|
|
76
|
+
## Shard Directory Location
|
|
77
|
+
|
|
78
|
+
Shards should be stored in a dedicated directory within your pipeline configuration:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
{pipeline-config}/shards/
|
|
82
|
+
├── stage-0-init.shard.md
|
|
83
|
+
├── stage-1-analysis.shard.md
|
|
84
|
+
├── stage-2-research.shard.md
|
|
85
|
+
├── stage-3-design.shard.md
|
|
86
|
+
└── ...
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Creating a New Shard
|
|
90
|
+
|
|
91
|
+
To create a shard for a new stage:
|
|
92
|
+
|
|
93
|
+
1. Copy the template format above
|
|
94
|
+
2. Fill in the stage-specific rules, quality gates, and anti-patterns
|
|
95
|
+
3. Define the time budget (as a percentage of total pipeline time)
|
|
96
|
+
4. List prerequisites (upstream promise tags)
|
|
97
|
+
5. Specify the skill to load (if applicable)
|
|
98
|
+
6. Define the promise tag this stage emits on completion
|
|
99
|
+
7. Save to the shards directory with the naming convention
|
|
100
|
+
|
|
101
|
+
## Shard Compilation
|
|
102
|
+
|
|
103
|
+
For complex pipelines, the master configuration file (e.g., CLAUDE.md) can be "compiled" into per-stage shards at pipeline start:
|
|
104
|
+
|
|
105
|
+
1. Read the master configuration
|
|
106
|
+
2. Extract stage-relevant rules
|
|
107
|
+
3. Generate shards with only the rules applicable to each stage
|
|
108
|
+
4. Each agent receives a focused, lightweight governance document instead of the full configuration
|
|
109
|
+
|
|
110
|
+
This reduces context load from hundreds of lines to 30-50 lines per stage.
|
|
111
|
+
|
|
112
|
+
## Best Practices
|
|
113
|
+
|
|
114
|
+
- Keep each shard under 100 lines for optimal context usage
|
|
115
|
+
- Include only rules relevant to the current stage
|
|
116
|
+
- Always include the promise tag for completion signaling
|
|
117
|
+
- Always include time budget to prevent stages from running indefinitely
|
|
118
|
+
- Review and update shards when pipeline rules change
|
package/index.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# keysarium-core Module Index
|
|
2
|
+
|
|
3
|
+
> Manifest of all modules in @dzhechkov/keysarium-core v1.0.0
|
|
4
|
+
|
|
5
|
+
## Module Registry
|
|
6
|
+
|
|
7
|
+
| Module | Version | Files | Trust Tier | Description |
|
|
8
|
+
|--------|---------|-------|------------|-------------|
|
|
9
|
+
| governance | 1.0 | 3 | Tier 1 — Structured | Constitution, shards, checkpoints |
|
|
10
|
+
| memory | 1.0 | 3 | Tier 1 — Structured | Reward-calibrated learning + dream cycles |
|
|
11
|
+
| orchestration | 1.0 | 4 | Tier 1 — Structured | Coordinator protocol + topologies + workers |
|
|
12
|
+
| verification | 1.0 | 3 | Tier 1 — Structured | Hash chains + judge attestation + audit trail |
|
|
13
|
+
| trust-tiers | 1.0 | 2 | Tier 1 — Structured | 4-tier classification + promotion |
|
|
14
|
+
| platform | 1.0 | 4 | Tier 0 — Advisory | Multi-platform adapter templates |
|
|
15
|
+
|
|
16
|
+
## File Manifest
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
@dzhechkov/keysarium-core/
|
|
20
|
+
├── package.json
|
|
21
|
+
├── README.md
|
|
22
|
+
├── index.md ← This file
|
|
23
|
+
│
|
|
24
|
+
├── governance/
|
|
25
|
+
│ ├── constitution.md ← v1.0 — Universal invariants
|
|
26
|
+
│ ├── shard-protocol.md ← v1.0 — Per-stage governance shards
|
|
27
|
+
│ └── checkpoint-protocol.md ← v1.0 — Checkpoints + promise tags
|
|
28
|
+
│
|
|
29
|
+
├── memory/
|
|
30
|
+
│ ├── memory-protocol.md ← v1.0 — memory_query + memory_store
|
|
31
|
+
│ ├── reward-tracker.md ← v1.0 — Analytics + pattern detection
|
|
32
|
+
│ └── dream-engine.md ← v1.0 — Background insight generation
|
|
33
|
+
│
|
|
34
|
+
├── orchestration/
|
|
35
|
+
│ ├── queen-protocol.md ← v1.0 — 10-step coordinator lifecycle
|
|
36
|
+
│ ├── topology-selection.md ← v1.0 — 6 topology types
|
|
37
|
+
│ ├── background-workers.md ← v1.0 — Non-blocking worker protocol
|
|
38
|
+
│ └── model-routing.md ← v1.0 — 3-tier model assignment
|
|
39
|
+
│
|
|
40
|
+
├── verification/
|
|
41
|
+
│ ├── witness-chain.md ← v1.0 — SHA-256 hash-chain
|
|
42
|
+
│ ├── judge-attestation.md ← v1.0 — Evaluator isolation proofs
|
|
43
|
+
│ └── audit-trail.md ← v1.0 — Evaluation history format
|
|
44
|
+
│
|
|
45
|
+
├── trust-tiers/
|
|
46
|
+
│ ├── tier-system.md ← v1.0 — 4-tier classification
|
|
47
|
+
│ └── promotion-protocol.md ← v1.0 — Tier advancement rules
|
|
48
|
+
│
|
|
49
|
+
└── platform/
|
|
50
|
+
├── adapter-registry.md ← v1.0 — Platform adapter definitions
|
|
51
|
+
└── templates/
|
|
52
|
+
├── cursor.md ← v1.0 — Cursor generation template
|
|
53
|
+
├── opencode.md ← v1.0 — OpenCode generation template
|
|
54
|
+
└── copilot.md ← v1.0 — GitHub Copilot generation template
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Protocol Version History
|
|
58
|
+
|
|
59
|
+
| Version | Date | Changes |
|
|
60
|
+
|---------|------|---------|
|
|
61
|
+
| 1.0 | 2026-03-01 | Initial extraction from Keysarium v1.1.x and lib/ protocols |
|
|
62
|
+
|
|
63
|
+
## Dependency Graph
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
governance ───> (standalone, no internal deps)
|
|
67
|
+
memory ───> (standalone, no internal deps)
|
|
68
|
+
orchestration ───> (standalone, no internal deps)
|
|
69
|
+
verification ───> (standalone, no internal deps)
|
|
70
|
+
trust-tiers ───> (standalone, no internal deps)
|
|
71
|
+
platform ───> (standalone, no internal deps)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
All modules are independent. A consumer may use any subset of modules without importing the others.
|
|
75
|
+
|
|
76
|
+
## Schema Compatibility
|
|
77
|
+
|
|
78
|
+
All JSON schemas defined in this package use `"version": "1.0"` as a schema version field. Consumers should check this field and warn if it does not match expected version.
|
|
79
|
+
|
|
80
|
+
## Terminology Mapping
|
|
81
|
+
|
|
82
|
+
When adapting core protocols for a specific domain:
|
|
83
|
+
|
|
84
|
+
| Core Term | Replace With | Example |
|
|
85
|
+
|-----------|-------------|---------|
|
|
86
|
+
| stage | Your pipeline unit | "phase" (Keysarium), "layer" (BTO) |
|
|
87
|
+
| project | Your work unit | "research" (Keysarium), "artifact" (BTO) |
|
|
88
|
+
| domain | Your category system | "banking/retail" (Keysarium), "skill type" (BTO) |
|
|
89
|
+
| skill | Your capability unit | "explore/research" (Keysarium), "build/test" (BTO) |
|