@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
@@ -10,6 +10,13 @@
10
10
  6. [Agent Swarm Architecture](#agent-swarm-architecture)
11
11
  7. [Модульность для переиспользования](#модульность-для-переиспользования)
12
12
  8. [Сравнение с claude.ai](#сравнение-с-claudeai)
13
+ 9. [Governance System](#governance-system)
14
+ 10. [Memory & Learning System](#memory--learning-system)
15
+ 11. [Verification System](#verification-system)
16
+ 12. [Trust Tier System](#trust-tier-system)
17
+ 13. [Background Workers](#background-workers)
18
+ 14. [Multi-Platform Support](#multi-platform-support)
19
+ 15. [keysarium-core Package](#keysarium-core-package)
13
20
 
14
21
  ---
15
22
 
@@ -704,3 +711,177 @@ Product Keysarium 2026 спроектирован для работы в Claude
704
711
  | Командная работа с git | Claude Code |
705
712
  | Прототипирование скилла | claude.ai (быстрый feedback loop) |
706
713
  | Production pipeline | Claude Code (воспроизводимость) |
714
+
715
+ ---
716
+
717
+ ## Governance System
718
+
719
+ ### Constitution & Shards
720
+
721
+ Каждая фаза загружает свой governance shard из `.claude/shards/`:
722
+
723
+ ```
724
+ .claude/shards/
725
+ ├── phase-0-discovery.shard.md
726
+ ├── phase-1-explore.shard.md
727
+ ├── phase-2-research.shard.md
728
+ ├── phase-25-cjm.shard.md
729
+ ├── phase-3-solve.shard.md
730
+ ├── phase-4-architecture.shard.md
731
+ ├── phase-5-presentation.shard.md
732
+ ├── bto-evaluation.shard.md
733
+ └── feature-adr.shard.md
734
+ ```
735
+
736
+ Shard содержит: time budget, skill to load, prerequisites, quality gates, promise tag. Решает проблему context drift при длинных сессиях.
737
+
738
+ ### Semantic Completion Promises
739
+
740
+ Каждый checkpoint включает машинно-читаемый `<promise>` тег:
741
+
742
+ | Фаза | Promise Tag |
743
+ |------|------------|
744
+ | Phase 0 | `DISCOVERY_COMPLETE` |
745
+ | Phase 1 | `CASE_EXPLORED` |
746
+ | Phase 2 | `RESEARCH_PARANOID_PASSED` |
747
+ | Phase 2.5 | `CJM_VALIDATED` |
748
+ | Phase 3 | `SOLUTION_DESIGNED` |
749
+ | Phase 4 | `ARCHITECTURE_DEFINED` |
750
+ | Phase 5 | `PRESENTATION_READY` |
751
+
752
+ ---
753
+
754
+ ## Memory & Learning System
755
+
756
+ ### Reward-calibrated Learning
757
+
758
+ Персистентная память в `.keysarium/memory/`:
759
+
760
+ 1. **Pre-phase:** `memory_query()` загружает релевантные паттерны из прошлых кейсов
761
+ 2. **Post-checkpoint:** `memory_store()` сохраняет результат с reward score (0.0-1.0)
762
+
763
+ Reward mapping: "ок" → 1.0, minor adjustments → 0.7, significant rework → 0.3, full restart → 0.0
764
+
765
+ ### Cross-phase Feedback Loops
766
+
767
+ 6 именованных loops формализуют передачу данных:
768
+
769
+ | Loop | Direction | Key Variable |
770
+ |------|-----------|-------------|
771
+ | CJM → Solve | Phase 2.5 → 3 | `{CHOSEN_CJM}` |
772
+ | Research → Presentation | Phase 2 → 5 | Verified sources |
773
+ | Discovery → All | Phase 0 → 1-5 | `{DOMAIN}`, `{PRIMARY_USER}` |
774
+ | Solve → Architecture | Phase 3 → 4 | `{SOLUTION_CONCEPT}` |
775
+ | BTO Judges → Optimizer | Layer 2 → Optimize | `{WEAK_DIMENSIONS}` |
776
+ | History → Discovery | Past → Phase 0 | Domain patterns |
777
+
778
+ ### Dream Cycles
779
+
780
+ Background pattern analysis engine:
781
+
782
+ ```mermaid
783
+ graph LR
784
+ A[Pattern Collection] --> B[Trigger Check]
785
+ B -->|Volume >= 20| C[DreamEngine]
786
+ B -->|Time >= 60 min| C
787
+ B -->|Quality gate fail| C
788
+ C --> D[Concept Graph]
789
+ D --> E[Insight Generation]
790
+ E --> F[Applied at next pipeline start]
791
+ ```
792
+
793
+ Инсайты хранятся в `.keysarium/insights/` (max 10 файлов, chronological retention).
794
+
795
+ ---
796
+
797
+ ## Verification System
798
+
799
+ ### SHA-256 Witness Chain
800
+
801
+ Каждый phase artifact получает hash, chain связывает артефакты:
802
+
803
+ ```
804
+ Phase 0: hash_0 = SHA-256(00_product_discovery.md)
805
+ Phase 1: hash_1 = SHA-256(01_case_brief.md + hash_0)
806
+ Phase 2: hash_2 = SHA-256(02_research_findings.md + hash_1)
807
+ ...
808
+ ```
809
+
810
+ Хранится в `researches/<slug>/.witness-chain.json`. Невозможно подменить промежуточный артефакт без разрыва цепочки.
811
+
812
+ ### BTO Judge Attestation
813
+
814
+ Криптографическое доказательство независимости судей в `.judge-attestations.json`:
815
+ - Каждый judge записывает оценку с SHA-256 hash ДО того, как видит оценки других
816
+ - Timestamps доказуемо верифицируют изоляцию judges
817
+
818
+ ---
819
+
820
+ ## Trust Tier System
821
+
822
+ | Tier | Label | Requirements |
823
+ |------|-------|-------------|
824
+ | 3 | Verified | Eval test suites + deterministic validation |
825
+ | 2 | Validated | /bto-test Layer 2 score >= 7.0 |
826
+ | 1 | Structured | SKILL.md + references/ or modules/ |
827
+ | 0 | Advisory | Only SKILL.md |
828
+
829
+ Повышение: `/bto-test .claude/skills/<name>/` → score >= 7.0 → Tier 2 → score >= 8.5 + eval tests → Tier 3.
830
+
831
+ ---
832
+
833
+ ## Background Workers
834
+
835
+ ```mermaid
836
+ graph TB
837
+ CMD["/workers start consolidate"] --> REG[Registry<br/>.keysarium/workers/registry.json]
838
+ REG --> W1[Worker: consolidate<br/>model=sonnet]
839
+ REG --> W2[Worker: health-check<br/>model=haiku]
840
+ REG --> W3[Worker: dream-cycle<br/>model=sonnet]
841
+ W1 --> OUT1[.keysarium/workers/{id}/]
842
+ W2 --> OUT2[.keysarium/workers/{id}/]
843
+ W3 --> OUT3[.keysarium/workers/{id}/]
844
+ ```
845
+
846
+ Max 3 concurrent, strict isolation (write only to .keysarium/workers/), never opus.
847
+
848
+ ---
849
+
850
+ ## Multi-Platform Support
851
+
852
+ ```mermaid
853
+ graph LR
854
+ CORE[Keysarium Skills + Rules] --> CC[Claude Code<br/>.claude/]
855
+ CORE --> CUR[Cursor<br/>.cursorrules]
856
+ CORE --> OC[OpenCode<br/>.opencode/]
857
+ CORE --> COP[GitHub Copilot<br/>.github/copilot-instructions.md]
858
+ ```
859
+
860
+ `/init-platform --platform <name>` генерирует platform-specific конфигурации. Skills и rules -- тот же markdown, меняется только формат загрузки.
861
+
862
+ ---
863
+
864
+ ## keysarium-core Package
865
+
866
+ 3-package architecture:
867
+
868
+ ```
869
+ @dzhechkov/keysarium-core ← Domain-agnostic framework
870
+ ↑ ↑
871
+ peerDep peerDep
872
+ | |
873
+ @dzhechkov/keysarium @dzhechkov/skills-bto
874
+ ```
875
+
876
+ Core modules (22 files):
877
+
878
+ | Module | Files | Purpose |
879
+ |--------|-------|---------|
880
+ | governance/ | 3 | Constitution, shard protocol, checkpoint protocol |
881
+ | memory/ | 3 | Memory protocol, reward tracker, dream engine |
882
+ | orchestration/ | 4 | Queen protocol, topologies, workers, model routing |
883
+ | verification/ | 3 | Witness chain, judge attestation, audit trail |
884
+ | trust-tiers/ | 2 | Tier system, promotion protocol |
885
+ | platform/ | 4 | Adapter registry + templates |
886
+
887
+ All protocols are domain-agnostic -- any team can build custom multi-agent pipelines.
@@ -13,6 +13,11 @@
13
13
  9. [Admin Flow: Расширение пайплайна новой фазой](#admin-flow-расширение-пайплайна-новой-фазой)
14
14
  10. [Admin Flow: Массовый harvest](#admin-flow-массовый-harvest)
15
15
  11. [Error Flows](#error-flows)
16
+ 12. [User Flow: BTO — Build-Test-Optimize](#user-flow-bto--build-test-optimize)
17
+ 13. [User Flow: Feature ADR](#user-flow-feature-adr)
18
+ 14. [User Flow: Background Workers](#user-flow-background-workers)
19
+ 15. [User Flow: Dream Cycles](#user-flow-dream-cycles)
20
+ 16. [User Flow: Brain Export/Import](#user-flow-brain-exportimport)
16
21
 
17
22
  ---
18
23
 
@@ -923,3 +928,233 @@ flowchart TD
923
928
  | Anti-pattern обнаружен | Нет (предупреждение) | Флаг + автоматическое исправление |
924
929
  | "Just add GPT" в решении | Нет (предупреждение) | Запросить конкретные модели + pipeline |
925
930
  | Непроверенное утверждение | Нет (маркировка) | `[UNVERIFIED]` + флаг |
931
+
932
+ ---
933
+
934
+ ## User Flow: BTO — Build-Test-Optimize
935
+
936
+ ### Sequence Diagram
937
+
938
+ ```mermaid
939
+ sequenceDiagram
940
+ actor U as User
941
+ participant C as Claude (/bto)
942
+ participant FS as File System
943
+ participant J1 as Judge 1 (Expert)
944
+ participant J2 as Judge 2 (Critic)
945
+ participant J3 as Judge 3 (Auditor)
946
+
947
+ U->>C: /bto .claude/skills/my-skill/
948
+
949
+ Note over C: ═══ BUILD ═══
950
+ C->>FS: Read SKILL.md
951
+ C->>C: Генерация/улучшение артефакта
952
+ C->>FS: Write улучшенный SKILL.md
953
+ C-->>U: BUILD complete
954
+
955
+ Note over C: ═══ TEST (Layer 0) ═══
956
+ C->>C: 71 deterministic checks (haiku)
957
+ alt Layer 0 PASS
958
+ Note over C: ═══ TEST (Layer 1) ═══
959
+ C->>C: Semantic baseline (haiku)
960
+ else Layer 0 FAIL
961
+ C->>C: Auto-retry (до 3 раз)
962
+ end
963
+
964
+ Note over C: ═══ TEST (Layer 2) ═══
965
+ par 3 judges parallel (sonnet)
966
+ C->>J1: Domain Expert evaluation
967
+ C->>J2: Critic evaluation
968
+ C->>J3: Completeness Auditor
969
+ end
970
+ J1-->>C: Score + rationale
971
+ J2-->>C: Score + rationale
972
+ J3-->>C: Score + rationale
973
+ C->>C: Weighted average (0.4 / 0.3 / 0.3)
974
+ C-->>U: TEST score: X.X/10
975
+
976
+ Note over C: ═══ OPTIMIZE ═══
977
+ loop 3 rounds
978
+ C->>C: Mutation + evaluation
979
+ C->>C: Check delta > 0.5
980
+ end
981
+ C-->>U: OPTIMIZE complete, final score: Y.Y/10
982
+ ```
983
+
984
+ ### Step by Step
985
+
986
+ **Шаг 1.** Запуск BTO:
987
+ ```
988
+ /bto .claude/skills/my-skill/
989
+ ```
990
+
991
+ **Шаг 2.** BUILD — генерация или улучшение артефакта.
992
+
993
+ **Шаг 3.** TEST — 3-уровневая оценка:
994
+ - Layer 0: структурные проверки (haiku)
995
+ - Layer 1: семантический базовый уровень (haiku)
996
+ - Layer 2: панель из 3 судей (sonnet), работают изолированно
997
+
998
+ **Шаг 4.** OPTIMIZE — эволюционная оптимизация за 3 раунда. Останавливается при delta ≤ 0.5 три раза подряд.
999
+
1000
+ ---
1001
+
1002
+ ## User Flow: Feature ADR
1003
+
1004
+ ### Sequence Diagram
1005
+
1006
+ ```mermaid
1007
+ sequenceDiagram
1008
+ actor U as User
1009
+ participant C as Claude (/feature-adr)
1010
+ participant FS as File System
1011
+
1012
+ U->>C: /feature-adr Add user authentication
1013
+
1014
+ Note over C: Step 0: Complexity Router (haiku)
1015
+ C->>C: Classify: S / M / L / XL
1016
+ C-->>U: Checkpoint 0: Tier = M (4-10 files)
1017
+ U->>C: "ок"
1018
+
1019
+ Note over C: Step 1: Requirements (sonnet)
1020
+ C->>FS: Write features/add-user-auth/01_requirements.md
1021
+ C-->>U: Checkpoint 1
1022
+ U->>C: "ок"
1023
+
1024
+ Note over C: Step 3: ADR (opus) [M tier — skip Step 2]
1025
+ C->>FS: Write features/add-user-auth/03_adr/001-auth-strategy.md
1026
+ C-->>U: Checkpoint 3
1027
+ U->>C: "ок"
1028
+
1029
+ Note over C: Step 5: Architecture (opus)
1030
+ C->>FS: Write features/add-user-auth/05_architecture.md
1031
+ C-->>U: Checkpoint 5
1032
+ U->>C: "ок"
1033
+
1034
+ Note over C: Step 6: Implementation Plan (sonnet)
1035
+ C->>FS: Write features/add-user-auth/06_implementation_plan.md
1036
+
1037
+ Note over C: Step 7: Code (opus)
1038
+ C->>C: Implement code changes in codebase
1039
+ C->>FS: Write features/add-user-auth/07_code_changes/change_manifest.md
1040
+
1041
+ Note over C: Step 8: QE (sonnet)
1042
+ C->>FS: Write features/add-user-auth/08_qe_report.md
1043
+ C-->>U: Feature complete!
1044
+ ```
1045
+
1046
+ ### Complexity Tiers
1047
+
1048
+ | Tier | Scope | Шаги |
1049
+ |------|-------|------|
1050
+ | **S** | 1-3 файла, 1 домен | 0→1→6→7→8 |
1051
+ | **M** | 4-10 файлов, 1-2 домена | 0→1→3→5→6→7→8 |
1052
+ | **L** | 11-30 файлов, 2-4 домена | Полный pipeline |
1053
+ | **XL** | 30+ файлов, cross-cutting | Full DAG + multi-agent |
1054
+
1055
+ ---
1056
+
1057
+ ## User Flow: Background Workers
1058
+
1059
+ ### Sequence Diagram
1060
+
1061
+ ```mermaid
1062
+ sequenceDiagram
1063
+ actor U as User
1064
+ participant C as Claude (/workers)
1065
+ participant FS as File System
1066
+ participant W as Background Worker
1067
+
1068
+ U->>C: /workers start consolidate
1069
+ C->>FS: Check registry (max 3 workers)
1070
+ C->>FS: Create .keysarium/workers/{id}/
1071
+ C->>W: Spawn agent (model=sonnet)
1072
+ W->>FS: Read researches/*
1073
+ W->>W: Pattern consolidation
1074
+ W->>FS: Write .keysarium/workers/{id}/output.json
1075
+ W->>FS: Update status.json
1076
+ C-->>U: Worker started: wkr-20260301-143022-consolidate
1077
+
1078
+ U->>C: /workers status
1079
+ C->>FS: Read registry.json + status files
1080
+ C-->>U: 1 active, 0 completed, 2 slots available
1081
+
1082
+ U->>C: /workers stop wkr-20260301-143022-consolidate
1083
+ C->>FS: Update registry
1084
+ C-->>U: Worker stopped
1085
+ ```
1086
+
1087
+ ### Типы воркеров
1088
+
1089
+ | Тип | Модель | Назначение |
1090
+ |-----|--------|-----------|
1091
+ | `consolidate` | sonnet | Консолидация паттернов из исследований |
1092
+ | `health-check` | haiku | Проверка здоровья системы |
1093
+ | `export-brain` | haiku | Фоновый экспорт знаний |
1094
+ | `dream-cycle` | sonnet | Dream cycle (concept graph + insights) |
1095
+
1096
+ ---
1097
+
1098
+ ## User Flow: Dream Cycles
1099
+
1100
+ ### Sequence Diagram
1101
+
1102
+ ```mermaid
1103
+ sequenceDiagram
1104
+ actor U as User
1105
+ participant C as Claude (/dream)
1106
+ participant FS as File System
1107
+
1108
+ U->>C: /dream run
1109
+ C->>FS: Read .keysarium/memory/**
1110
+ C->>C: Build concept graph
1111
+ C->>C: Cross-domain pattern analysis
1112
+ C->>C: Generate insights (4 types)
1113
+ C->>FS: Write .keysarium/insights/dream-20260301-143022.json
1114
+ C->>FS: Update trigger-state.json (reset counters)
1115
+ C-->>U: Dream complete: 5 insights generated
1116
+
1117
+ U->>C: /dream insights
1118
+ C->>FS: Read .keysarium/insights/dream-*.json
1119
+ C-->>U: Insights list (sorted by recency)
1120
+
1121
+ U->>C: /dream status
1122
+ C->>FS: Read trigger-state.json
1123
+ C-->>U: Records since last dream: 15/20, Time: 45/60 min
1124
+ ```
1125
+
1126
+ ### Типы инсайтов
1127
+
1128
+ | Тип | Пример |
1129
+ |-----|--------|
1130
+ | Performance | "Phase 2 takes 2x longer for banking domain" |
1131
+ | Effectiveness | "TRIZ produces higher scores than Game Theory for retail" |
1132
+ | Preference | "CJM Variant B selected in 70% of enterprise cases" |
1133
+ | Anti-pattern | "Phase 5 consistently gets rework when HITL skipped in Phase 3" |
1134
+
1135
+ ---
1136
+
1137
+ ## User Flow: Brain Export/Import
1138
+
1139
+ ### Sequence Diagram
1140
+
1141
+ ```mermaid
1142
+ sequenceDiagram
1143
+ actor U as User
1144
+ participant C as Claude
1145
+ participant FS as File System
1146
+
1147
+ Note over U,C: === EXPORT ===
1148
+ U->>C: /brain-export all
1149
+ C->>FS: Read researches/*, .keysarium/memory/*, TOOLKIT_HARVEST.md
1150
+ C->>C: Assemble: skills + patterns + research summaries + metrics
1151
+ C->>FS: Write keysarium-brain.json
1152
+ C-->>U: Brain exported: 15 patterns, 3 domain profiles
1153
+
1154
+ Note over U,C: === IMPORT (другой проект) ===
1155
+ U->>C: /brain-import keysarium-brain.json
1156
+ C->>FS: Read keysarium-brain.json
1157
+ C->>C: Selective merge (merge-not-overwrite)
1158
+ C->>FS: Merge into .keysarium/memory/
1159
+ C-->>U: Imported: 12 patterns merged, 3 skipped (duplicates)
1160
+ ```