izanagi-ai 2.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.
Files changed (195) hide show
  1. package/AGENTS.md +53 -0
  2. package/CHANGELOG.md +198 -0
  3. package/LICENSE +21 -0
  4. package/README.md +96 -0
  5. package/ROADMAP.md +131 -0
  6. package/RULES.md +202 -0
  7. package/SYSTEM.md +201 -0
  8. package/agents/INDEX.md +40 -0
  9. package/agents/architect-agent.json +15 -0
  10. package/agents/bug-hunter-agent.json +14 -0
  11. package/agents/database-agent.json +14 -0
  12. package/agents/devops-agent.json +15 -0
  13. package/agents/docs-agent.json +15 -0
  14. package/agents/pm-agent.json +14 -0
  15. package/agents/professor-agent.json +15 -0
  16. package/agents/security-agent.json +14 -0
  17. package/agents/senior-engineer-agent.json +16 -0
  18. package/agents/techlead-agent.json +15 -0
  19. package/architecture/clean-architecture.md +98 -0
  20. package/architecture/cqrs-specialist.md +102 -0
  21. package/architecture/ddd-specialist.md +97 -0
  22. package/architecture/event-driven-architect.md +79 -0
  23. package/architecture/hexagonal-architecture.md +96 -0
  24. package/architecture/microservices-expert.md +83 -0
  25. package/architecture/monolith-expert.md +67 -0
  26. package/architecture/repository-pattern.md +73 -0
  27. package/architecture/unit-of-work.md +92 -0
  28. package/backend/README.md +29 -0
  29. package/bin/nexus.js +8 -0
  30. package/core/compression-engine.md +194 -0
  31. package/core/context-engine.md +239 -0
  32. package/core/decision-engine.md +377 -0
  33. package/core/evolution-engine.md +169 -0
  34. package/core/planning-engine.md +201 -0
  35. package/core/quality-gates.md +233 -0
  36. package/core/reflection-engine.md +182 -0
  37. package/core/skill-resolver.json +169 -0
  38. package/core/token-manager.md +152 -0
  39. package/database/database-engineer.md +244 -0
  40. package/database/mysql-specialist.md +61 -0
  41. package/database/postgresql-specialist.md +70 -0
  42. package/database/redis-specialist.md +73 -0
  43. package/database/sql-optimizer.md +95 -0
  44. package/database/sqlserver-specialist.md +69 -0
  45. package/devops/ci-cd-specialist.md +101 -0
  46. package/devops/devops-engineer.md +358 -0
  47. package/devops/docker-expert.md +105 -0
  48. package/devops/git-expert.md +76 -0
  49. package/devops/git-flow-specialist.md +71 -0
  50. package/devops/kubernetes-specialist.md +84 -0
  51. package/devops/linux-specialist.md +82 -0
  52. package/devops/windows-specialist.md +43 -0
  53. package/dist/cli/commands/compile.d.ts +2 -0
  54. package/dist/cli/commands/compile.d.ts.map +1 -0
  55. package/dist/cli/commands/compile.js +44 -0
  56. package/dist/cli/commands/compile.js.map +1 -0
  57. package/dist/cli/commands/doctor.d.ts +2 -0
  58. package/dist/cli/commands/doctor.d.ts.map +1 -0
  59. package/dist/cli/commands/doctor.js +88 -0
  60. package/dist/cli/commands/doctor.js.map +1 -0
  61. package/dist/cli/commands/init.d.ts +2 -0
  62. package/dist/cli/commands/init.d.ts.map +1 -0
  63. package/dist/cli/commands/init.js +26 -0
  64. package/dist/cli/commands/init.js.map +1 -0
  65. package/dist/cli/commands/list.d.ts +2 -0
  66. package/dist/cli/commands/list.d.ts.map +1 -0
  67. package/dist/cli/commands/list.js +50 -0
  68. package/dist/cli/commands/list.js.map +1 -0
  69. package/dist/cli/commands/run.d.ts +2 -0
  70. package/dist/cli/commands/run.d.ts.map +1 -0
  71. package/dist/cli/commands/run.js +49 -0
  72. package/dist/cli/commands/run.js.map +1 -0
  73. package/dist/cli/index.d.ts +2 -0
  74. package/dist/cli/index.d.ts.map +1 -0
  75. package/dist/cli/index.js +72 -0
  76. package/dist/cli/index.js.map +1 -0
  77. package/dist/index.d.ts +3 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +3 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/installer.d.ts +5 -0
  82. package/dist/installer.d.ts.map +1 -0
  83. package/dist/installer.js +86 -0
  84. package/dist/installer.js.map +1 -0
  85. package/dist/postinstall.d.ts +2 -0
  86. package/dist/postinstall.d.ts.map +1 -0
  87. package/dist/postinstall.js +8 -0
  88. package/dist/postinstall.js.map +1 -0
  89. package/frontend/README.md +19 -0
  90. package/memory/context-recovery.md +49 -0
  91. package/memory/conversation-summarizer.md +65 -0
  92. package/memory/long-term-project-memory.md +58 -0
  93. package/memory/memory-manager.md +299 -0
  94. package/memory/session-compression.md +182 -0
  95. package/memory/smart-recall.md +37 -0
  96. package/optimization/compact-example.md +87 -0
  97. package/optimization/cost-optimizer.md +53 -0
  98. package/optimization/prompt-optimizer.md +194 -0
  99. package/optimization/token-audit.md +177 -0
  100. package/optimization/token-reducer.md +202 -0
  101. package/package.json +67 -0
  102. package/security/owasp-auditor.md +249 -0
  103. package/security/pentest-reviewer.md +109 -0
  104. package/security/security-engineer.md +238 -0
  105. package/skills/INDEX.md +434 -0
  106. package/skills/accessibility-reviewer.md +63 -0
  107. package/skills/agentic-coding.md +56 -0
  108. package/skills/ai-agent/SKILL.md +107 -0
  109. package/skills/ai-agent-dev/SKILL.md +117 -0
  110. package/skills/alternative-solution-generator.md +72 -0
  111. package/skills/architecture-patterns/SKILL.md +113 -0
  112. package/skills/breaking-change-detector.md +84 -0
  113. package/skills/bug-hunter.md +234 -0
  114. package/skills/bug-prevention.md +75 -0
  115. package/skills/chaos-engineering/SKILL.md +108 -0
  116. package/skills/clean-code-validator.md +218 -0
  117. package/skills/cloud-architect/SKILL.md +78 -0
  118. package/skills/cloud-infra/SKILL.md +99 -0
  119. package/skills/code-auditor.md +24 -0
  120. package/skills/complexity-analyzer.md +102 -0
  121. package/skills/confidence-estimator.md +53 -0
  122. package/skills/continuous-improvement.md +46 -0
  123. package/skills/continuous-learning-engine.md +51 -0
  124. package/skills/cto-advisor.md +66 -0
  125. package/skills/data-engineer/SKILL.md +76 -0
  126. package/skills/data-engineering/SKILL.md +82 -0
  127. package/skills/debug-specialist.md +215 -0
  128. package/skills/dependency-analyzer.md +78 -0
  129. package/skills/design-pattern-advisor.md +78 -0
  130. package/skills/documentation-writer.md +66 -0
  131. package/skills/dry-kiss-yagni-validator.md +114 -0
  132. package/skills/economia-tokens/SKILL.md +40 -0
  133. package/skills/er-diagram-builder.md +85 -0
  134. package/skills/feature-flags/SKILL.md +95 -0
  135. package/skills/frontend/SKILL.md +327 -0
  136. package/skills/frontend-dev/SKILL.md +178 -0
  137. package/skills/graphql/SKILL.md +104 -0
  138. package/skills/hallucination-detection.md +49 -0
  139. package/skills/handoff-sessao/SKILL.md +32 -0
  140. package/skills/i18n-l10n/SKILL.md +103 -0
  141. package/skills/iac-terraform/SKILL.md +98 -0
  142. package/skills/legacy-migration/SKILL.md +91 -0
  143. package/skills/logging-expert.md +78 -0
  144. package/skills/mcp-server-dev.md +33 -0
  145. package/skills/memoria-projeto/SKILL.md +49 -0
  146. package/skills/mobile-dev/SKILL.md +82 -0
  147. package/skills/mobile-engineer/SKILL.md +74 -0
  148. package/skills/monitoring-specialist.md +59 -0
  149. package/skills/observability-expert.md +60 -0
  150. package/skills/performance-optimizer.md +239 -0
  151. package/skills/principal-engineer.md +55 -0
  152. package/skills/privacy-engineer/SKILL.md +79 -0
  153. package/skills/professor-modo/SKILL.md +33 -0
  154. package/skills/project-manager.md +74 -0
  155. package/skills/prompt-engineering.md +27 -0
  156. package/skills/qa/SKILL.md +231 -0
  157. package/skills/qa-engineer/SKILL.md +222 -0
  158. package/skills/readme-generator.md +42 -0
  159. package/skills/refactoring-specialist.md +250 -0
  160. package/skills/release-planner.md +70 -0
  161. package/skills/requirement-analyzer.md +65 -0
  162. package/skills/risk-analyzer.md +73 -0
  163. package/skills/root-cause-analyzer.md +210 -0
  164. package/skills/scalability-expert.md +73 -0
  165. package/skills/security-privacy/SKILL.md +98 -0
  166. package/skills/self-correction.md +54 -0
  167. package/skills/self-critique.md +42 -0
  168. package/skills/senior-code-reviewer.md +193 -0
  169. package/skills/sequence-diagram-builder.md +56 -0
  170. package/skills/serverless-edge/SKILL.md +103 -0
  171. package/skills/software-architect.md +356 -0
  172. package/skills/solid-validator.md +332 -0
  173. package/skills/sre-reliability/SKILL.md +115 -0
  174. package/skills/staff-engineer.md +61 -0
  175. package/skills/task-planner.md +61 -0
  176. package/skills/tech-lead.md +59 -0
  177. package/skills/technical-debt-analyzer.md +81 -0
  178. package/skills/technical-writer.md +39 -0
  179. package/skills/tradeoff-analyzer.md +79 -0
  180. package/skills/uml-generator.md +72 -0
  181. package/skills/ux-reviewer.md +61 -0
  182. package/skills/wasm/SKILL.md +133 -0
  183. package/skills/web-perf-engineer/SKILL.md +75 -0
  184. package/skills/web-perf-seo/SKILL.md +111 -0
  185. package/skills/websocket-realtime/SKILL.md +107 -0
  186. package/teaching/adaptive-teaching.md +37 -0
  187. package/teaching/code-explainer.md +172 -0
  188. package/teaching/interactive-teaching.md +41 -0
  189. package/teaching/learning-tracker.md +63 -0
  190. package/teaching/mentor-mode.md +200 -0
  191. package/teaching/professor-mode.md +222 -0
  192. package/testing/e2e-test-engineer.md +68 -0
  193. package/testing/integration-test-engineer.md +74 -0
  194. package/testing/mocking-specialist.md +78 -0
  195. package/testing/unit-test-engineer.md +209 -0
@@ -0,0 +1,92 @@
1
+ # Architecture: Unit of Work
2
+
3
+ > Version 1.0.0 | Priority: Medium
4
+ > Dependencies: Repository Pattern
5
+ > Compatibility: ">=1.0.0"
6
+
7
+ ---
8
+
9
+ ## Identity
10
+
11
+ Unit of Work maintains a list of objects affected by a business transaction and coordinates writing changes as a single atomic unit. Ensures all changes succeed or fail together.
12
+
13
+ ---
14
+
15
+ ## Implementation
16
+
17
+ ```php
18
+ class UnitOfWork
19
+ {
20
+ private array $new = [];
21
+ private array $dirty = [];
22
+ private array $deleted = [];
23
+
24
+ public function registerNew(object $entity): void
25
+ {
26
+ $this->new[] = $entity;
27
+ }
28
+
29
+ public function registerDirty(object $entity): void
30
+ {
31
+ if (!in_array($entity, $this->dirty, true)) {
32
+ $this->dirty[] = $entity;
33
+ }
34
+ }
35
+
36
+ public function registerDeleted(object $entity): void
37
+ {
38
+ $this->deleted[] = $entity;
39
+ }
40
+
41
+ public function commit(): void
42
+ {
43
+ $this->beginTransaction();
44
+ try {
45
+ foreach ($this->new as $entity) { $this->insert($entity); }
46
+ foreach ($this->dirty as $entity) { $this->update($entity); }
47
+ foreach ($this->deleted as $entity) { $this->delete($entity); }
48
+ $this->commitTransaction();
49
+ $this->clear();
50
+ } catch (\Exception $e) {
51
+ $this->rollbackTransaction();
52
+ throw $e;
53
+ }
54
+ }
55
+
56
+ public function clear(): void
57
+ {
58
+ $this->new = [];
59
+ $this->dirty = [];
60
+ $this->deleted = [];
61
+ }
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Usage with Repository
68
+
69
+ ```php
70
+ class OrderService
71
+ {
72
+ public function __construct(
73
+ private UnitOfWork $uow,
74
+ private OrderRepository $repo,
75
+ private EventDispatcher $events,
76
+ ) {}
77
+
78
+ public function placeOrder(Cart $cart): void
79
+ {
80
+ $order = Order::place($cart);
81
+ $this->repo->add($order); // registers in UoW
82
+ // More changes...
83
+ $this->uow->commit(); // all or nothing
84
+ }
85
+ }
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Changelog
91
+
92
+ ### 1.0.0 — Initial release. Implementation, usage pattern.
@@ -0,0 +1,29 @@
1
+ # Backend Skills
2
+
3
+ > Skills de desenvolvimento backend estão em `coding/`:
4
+
5
+ | Skill | Arquivo |
6
+ |-------|---------|
7
+ | Backend Engineer (geral) | `coding/backend-engineer.md` |
8
+ | Laravel Specialist | `coding/laravel-specialist.md` |
9
+ | PHP Specialist | `coding/php-specialist.md` |
10
+ | Python Specialist | `coding/python-specialist.md` |
11
+ | Node.js Specialist | `coding/nodejs-specialist.md` |
12
+ | Java Specialist | `coding/java-specialist.md` |
13
+ | C# Specialist | `coding/csharp-specialist.md` |
14
+ | API Designer | `coding/api-designer.md` |
15
+
16
+ ---
17
+
18
+ ## Sugestão de Reorganização
19
+
20
+ Para versão futura (2.0), mover:
21
+
22
+ ```
23
+ backend/backend-engineer.md ← de coding/backend-engineer.md
24
+ backend/laravel-specialist.md ← de coding/laravel-specialist.md
25
+ backend/api-designer.md ← de coding/api-designer.md
26
+ frontend/frontend-engineer.md ← de coding/frontend-engineer.md
27
+ frontend/react-specialist.md ← de coding/react-specialist.md
28
+ frontend/vue-specialist.md ← de coding/vue-specialist.md
29
+ ```
package/bin/nexus.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { runCLI } from '../src/cli/index.js';
4
+
5
+ runCLI(process.argv.slice(2)).catch((err) => {
6
+ console.error('\x1b[31m[NexusAI Error]:\x1b[0m', err.message || err);
7
+ process.exit(1);
8
+ });
@@ -0,0 +1,194 @@
1
+ # Core: Compression Engine
2
+
3
+ > Version 1.0.0
4
+ > Priority: High
5
+ > Dependencies: Token Manager
6
+ > Compatibility: ">=1.0.0"
7
+
8
+ ---
9
+
10
+ ## Identity
11
+
12
+ The Compression Engine is activated when the Token Manager detects that usage exceeds 70% of the budget. It applies lossy and lossless compression strategies to reduce token count while preserving semantic meaning and critical information.
13
+
14
+ ---
15
+
16
+ ## Goals
17
+
18
+ - Reduce token count by 30-50% when activated.
19
+ - Preserve 100% of decisions, security items, and action items.
20
+ - Eliminate 100% of redundancy, filler, and repetition.
21
+ - Complete compression in under 200ms.
22
+
23
+ ---
24
+
25
+ ## Compression Levels
26
+
27
+ | Level | Reduction | When Used | Risk |
28
+ |-------|-----------|-----------|------|
29
+ | **Lossless** | 10-20% | Budget at 70-80% | None — removes whitespace, shortens identifiers |
30
+ | **Light** | 20-35% | Budget at 80-90% | Low — summarizes examples, drops verbose explanations |
31
+ | **Aggressive** | 35-50% | Budget at 90-100% | Medium — drops non-critical examples, shortens code blocks |
32
+ | **Emergency** | 50-70% | Budget exceeded | High — keeps only decisions, security items, and action items |
33
+
34
+ ---
35
+
36
+ ## Compression Strategies
37
+
38
+ ### 1. Remove Filler (Lossless)
39
+
40
+ ```
41
+ Before: "I would recommend that you consider using..."
42
+ After: "Use..."
43
+
44
+ Before: "In order to achieve this goal, we need to..."
45
+ After: "To do this..."
46
+
47
+ Before: "It is important to note that the system should..."
48
+ After: "The system must..."
49
+ ```
50
+
51
+ ### 2. Condense Lists (Light)
52
+
53
+ ```
54
+ Before:
55
+ - First, create a new controller
56
+ - Second, add the validation rules
57
+ - Third, implement the service layer
58
+
59
+ After:
60
+ 1. Create controller
61
+ 2. Add validation
62
+ 3. Implement service
63
+ ```
64
+
65
+ ### 3. Summarize Code (Light)
66
+
67
+ ```
68
+ Before:
69
+ public function store(Request $request)
70
+ {
71
+ $validated = $request->validate([
72
+ 'name' => 'required|string|max:255',
73
+ 'email' => 'required|email|unique:users',
74
+ 'password' => 'required|min:8|confirmed',
75
+ ]);
76
+
77
+ $user = User::create($validated);
78
+
79
+ return response()->json($user, 201);
80
+ }
81
+
82
+ After:
83
+ // UserController::store — validates name, email, password → creates user → returns 201
84
+ ```
85
+
86
+ ### 4. Drop Repetition (Aggressive)
87
+
88
+ Remove content that has appeared verbatim in the last 3 responses. Track using a rolling hash of content blocks.
89
+
90
+ ### 5. Keyword-Only Memory (Emergency)
91
+
92
+ ```
93
+ Before:
94
+ "We decided to use JWT tokens stored in httpOnly cookies for authentication because it provides better XSS protection compared to localStorage. The refresh token endpoint is rate-limited to 5 requests per minute."
95
+
96
+ After:
97
+ "Auth: JWT in httpOnly cookies (XSS protection). Refresh rate-limited: 5/min."
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Decision Preservation
103
+
104
+ The following content types are **never** compressed below their minimum viable form:
105
+
106
+ | Content Type | Minimum Form |
107
+ |-------------|-------------|
108
+ | Security decision | Full — must remain readable |
109
+ | Vulnerability finding | Full — including severity and location |
110
+ | Action item | Full — including owner and deadline |
111
+ | Breaking change | Full — including migration path |
112
+ | Error explanation | Cause + fix (can remove stack trace) |
113
+ | User preference | Full — exact wording |
114
+
115
+ ---
116
+
117
+ ## Algorithm
118
+
119
+ ```
120
+ function compress(content, target_level):
121
+ if target_level == "lossless":
122
+ content = remove_filler(content)
123
+ content = shorten_markdown_headers(content)
124
+ content = remove_trailing_whitespace(content)
125
+
126
+ elif target_level == "light":
127
+ content = compress_lossless(content)
128
+ content = condense_lists(content)
129
+ content = summarize_examples(content, keep=2)
130
+ content = shorten_code_blocks(content, keep_signatures=true)
131
+
132
+ elif target_level == "aggressive":
133
+ content = compress_light(content)
134
+ content = drop_redundant_blocks(content)
135
+ content = summarize_code_blocks(content)
136
+ content = keep_only_first_sentence_of_explanations(content)
137
+
138
+ elif target_level == "emergency":
139
+ content = extract_decisions(content)
140
+ content = extract_security_items(content)
141
+ content = extract_action_items(content)
142
+ content = drop_everything_else(content)
143
+
144
+ return content
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Quality Check After Compression
150
+
151
+ 1. ✅ All decisions preserved?
152
+ 2. ✅ All security items preserved?
153
+ 3. ✅ All action items preserved?
154
+ 4. ✅ No grammatical errors introduced?
155
+ 5. ✅ Still understandable to the user?
156
+
157
+ If any check fails, revert to the previous level and retry.
158
+
159
+ ---
160
+
161
+ ## Metrics
162
+
163
+ | Metric | Target | How to Measure |
164
+ |--------|--------|---------------|
165
+ | Compression ratio | ≥ 2:1 (aggressive) | original size / compressed size |
166
+ | Decision loss rate | 0% | Count lost decisions |
167
+ | User comprehension | ≥ 95% | Follow-up user clarification rate |
168
+ | Compression speed | < 200ms | Execution time |
169
+
170
+ ---
171
+
172
+ ## Memory Hooks
173
+
174
+ ```yaml
175
+ on_compress:
176
+ - save: compression_log (level, ratio, items_dropped)
177
+ - save: preserved_decisions
178
+
179
+ on_failure:
180
+ - notify: Token Manager
181
+ - revert: to previous compression level
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Changelog
187
+
188
+ ### 1.0.0 (2026-07-17)
189
+
190
+ - Initial release
191
+ - 4 compression levels: lossless, light, aggressive, emergency
192
+ - Content-type preservation rules
193
+ - Rolling hash for repetition detection
194
+ - Quality check after every compression
@@ -0,0 +1,239 @@
1
+ # Core: Context Engine
2
+
3
+ > Version 1.0.0
4
+ > Priority: Critical
5
+ > Dependencies: Memory Manager, Token Manager
6
+ > Compatibility: ">=1.0.0"
7
+
8
+ ---
9
+
10
+ ## Identity
11
+
12
+ The Context Engine builds the minimal, high-signal context window for every task. It loads only what is relevant, compresses what is verbose, and discards what is noise. It is the gatekeeper of the token budget.
13
+
14
+ ---
15
+
16
+ ## Goals
17
+
18
+ - Load only relevant context (no waste).
19
+ - Compress verbose history without losing signal.
20
+ - Respect strict token limits per task.
21
+ - Provide the agent with everything needed, nothing extra.
22
+
23
+ ---
24
+
25
+ ## Context Window Structure
26
+
27
+ ```
28
+ ┌────────────────────────────────────────────┐
29
+ │ CONTEXT WINDOW │
30
+ │ │
31
+ │ 1. SYSTEM CONTEXT (200 tokens max) │
32
+ │ - Identity │
33
+ │ - Current task │
34
+ │ - Active skill chain │
35
+ │ │
36
+ │ 2. PROJECT CONTEXT (400 tokens max) │
37
+ │ - Project type │
38
+ │ - Tech stack │
39
+ │ - Architecture (from Software Arch.) │
40
+ │ - Conventions │
41
+ │ │
42
+ │ 3. MEMORY CONTEXT (300 tokens max) │
43
+ │ - Relevant decisions │
44
+ │ - Relevant errors │
45
+ │ - Relevant patterns │
46
+ │ │
47
+ │ 4. TASK CONTEXT (remaining budget) │
48
+ │ - User input │
49
+ │ - File contents (if referenced) │
50
+ │ - Previous output (if continuation) │
51
+ │ │
52
+ └────────────────────────────────────────────┘
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Workflow
58
+
59
+ ```
60
+ 1. Receive task and classification
61
+ ↓
62
+ 2. Load SYSTEM_CONTEXT
63
+ - Identity: who the agent is
64
+ - Task: what the user asked
65
+ - Chain: which skills will execute
66
+ ↓
67
+ 3. Load PROJECT_CONTEXT
68
+ - Query Project Memory for relevant data
69
+ - Load tech stack, architecture, conventions
70
+ ↓
71
+ 4. Load MEMORY_CONTEXT
72
+ - Query Long Term Memory for relevant patterns
73
+ - Query Knowledge Graph for related decisions
74
+ ↓
75
+ 5. Load TASK_CONTEXT
76
+ - User input (cleaned)
77
+ - Relevant files (truncated if > budget)
78
+ ↓
79
+ 6. COMPRESS if total > budget
80
+ - Apply priority-based compression
81
+ - Remove redundancy
82
+ - Summarize verbose sections
83
+ ↓
84
+ 7. DELIVER to Skill Executor
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Load Prioritization
90
+
91
+ When the context window is full, items are dropped in this order (last = kept):
92
+
93
+ 1. User input history (oldest first)
94
+ 2. Previous outputs (except last one)
95
+ 3. Memory context (lowest relevance score)
96
+ 4. Project context (general vs specific)
97
+ 5. Task context (current task)
98
+ 6. System context (never dropped)
99
+
100
+ ---
101
+
102
+ ## Compression Algorithm
103
+
104
+ ```
105
+ function compress(context, budget):
106
+ while size(context) > budget:
107
+ section = find_lowest_priority_section()
108
+
109
+ if section.type == "memory":
110
+ section = summarize(section)
111
+ // "We decided to use JWT instead of sessions"
112
+ // → "Decision: JWT > sessions"
113
+
114
+ elif section.type == "history":
115
+ section = drop_oldest_50_percent()
116
+
117
+ elif section.type == "file_content":
118
+ section = truncate_to_signature_lines()
119
+ // Keep: class declaration, method signatures
120
+ // Drop: implementation details
121
+
122
+ elif section.type == "project":
123
+ section = keep_only_active_tokens()
124
+ // Keep: current stack, relevant patterns
125
+ // Drop: inactive modules, old decisions
126
+
127
+ else:
128
+ section = remove_verbose_markdown()
129
+
130
+ return context
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Relevance Scoring
136
+
137
+ Each memory item is scored before loading:
138
+
139
+ ```
140
+ relevance = (keyword_match_count * 0.4)
141
+ + (recency_factor * 0.3)
142
+ + (task_type_match * 0.2)
143
+ + (frequency_factor * 0.1)
144
+
145
+ if relevance < 0.3:
146
+ skip loading (low signal)
147
+ elif relevance < 0.6:
148
+ load as compressed summary
149
+ else:
150
+ load in full
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Rules
156
+
157
+ ### Always
158
+
159
+ - ✅ Load minimal context for the task.
160
+ - ✅ Compress before delivering if budget exceeded.
161
+ - ✅ Prioritize current task over history.
162
+ - ✅ Keep system identity in every context window.
163
+
164
+ ### Never
165
+
166
+ - ❌ Load full conversation history.
167
+ - ❌ Load files not referenced by the task.
168
+ - ❌ Exceed the token budget.
169
+ - ❌ Drop system identity.
170
+
171
+ ---
172
+
173
+ ## Metrics
174
+
175
+ | Metric | Target | How to Measure |
176
+ |--------|--------|---------------|
177
+ | Context size vs budget | ≤ 100% | Compare window size to budget |
178
+ | Relevance of loaded memory | ≥ 0.6 | Average relevance score of loaded items |
179
+ | Compression ratio | ≥ 2:1 | Original size / compressed size |
180
+ | Dropped items rate | ≤ 20% | Items dropped vs total attempted |
181
+
182
+ ---
183
+
184
+ ## Token Budget
185
+
186
+ | Operation | Tokens |
187
+ |-----------|--------|
188
+ | Load system context | 50 |
189
+ | Load project context | 100 |
190
+ | Query memory | 80 |
191
+ | Score relevance | 40 |
192
+ | Compress (if needed) | 150 |
193
+ | **Total per build** | **~420** |
194
+
195
+ ---
196
+
197
+ ## Memory Hooks
198
+
199
+ ```yaml
200
+ on_build:
201
+ - load: system_identity
202
+ - load: project_tech_stack
203
+ - query: relevant_decisions
204
+
205
+ on_compress:
206
+ - save: compression_log
207
+ - notify: Token Manager
208
+
209
+ on_deliver:
210
+ - save: context_window_snapshot
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Reflection
216
+
217
+ ### Pre-delivery
218
+
219
+ - [ ] Is the context window minimal?
220
+ - [ ] Is any loaded item irrelevant?
221
+ - [ ] Can I compress further without losing signal?
222
+
223
+ ### Post-delivery
224
+
225
+ - [ ] Did the agent need context that was not loaded?
226
+ - [ ] Was any loaded context unused?
227
+ - [ ] Should relevance scoring be adjusted?
228
+
229
+ ---
230
+
231
+ ## Changelog
232
+
233
+ ### 1.0.0 (2026-07-17)
234
+
235
+ - Initial release
236
+ - 4-section context window structure
237
+ - Priority-based compression algorithm
238
+ - Relevance scoring for memory loading
239
+ - Budget enforcement before delivery