universal-agent-memory 0.4.0 → 0.5.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/dist/coordination/capability-router.d.ts +79 -0
- package/dist/coordination/capability-router.d.ts.map +1 -0
- package/dist/coordination/capability-router.js +324 -0
- package/dist/coordination/capability-router.js.map +1 -0
- package/dist/coordination/deploy-batcher.d.ts +64 -1
- package/dist/coordination/deploy-batcher.d.ts.map +1 -1
- package/dist/coordination/deploy-batcher.js +203 -39
- package/dist/coordination/deploy-batcher.js.map +1 -1
- package/dist/coordination/index.d.ts +1 -0
- package/dist/coordination/index.d.ts.map +1 -1
- package/dist/coordination/index.js +1 -0
- package/dist/coordination/index.js.map +1 -1
- package/dist/generators/template-loader.d.ts +105 -0
- package/dist/generators/template-loader.d.ts.map +1 -0
- package/dist/generators/template-loader.js +291 -0
- package/dist/generators/template-loader.js.map +1 -0
- package/dist/memory/serverless-qdrant.d.ts +102 -0
- package/dist/memory/serverless-qdrant.d.ts.map +1 -0
- package/dist/memory/serverless-qdrant.js +369 -0
- package/dist/memory/serverless-qdrant.js.map +1 -0
- package/dist/types/config.d.ts +1220 -15
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +92 -1
- package/dist/types/config.js.map +1 -1
- package/dist/types/coordination.d.ts +4 -4
- package/package.json +1 -1
- package/templates/CLAUDE.template.md +347 -370
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
/**
|
|
8
|
+
* Default section definitions.
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_SECTIONS = [
|
|
11
|
+
{ id: 'header', file: 'header.hbs', required: true, tokenEstimate: 50 },
|
|
12
|
+
{ id: 'directives', file: 'directives.hbs', required: true, tokenEstimate: 200 },
|
|
13
|
+
{ id: 'session-start', file: 'session-start.hbs', required: true, tokenEstimate: 150 },
|
|
14
|
+
{ id: 'coordination', file: 'coordination.hbs', required: true, tokenEstimate: 400 },
|
|
15
|
+
{ id: 'decision-loop', file: 'decision-loop.hbs', required: true, tokenEstimate: 300 },
|
|
16
|
+
{ id: 'memory-system', file: 'memory-system.hbs', required: true, tokenEstimate: 500 },
|
|
17
|
+
{ id: 'worktree', file: 'worktree.hbs', required: true, tokenEstimate: 200 },
|
|
18
|
+
{ id: 'parallel-review', file: 'parallel-review.hbs', required: true, tokenEstimate: 250 },
|
|
19
|
+
{ id: 'triggers', file: 'triggers.hbs', required: true, tokenEstimate: 150 },
|
|
20
|
+
{
|
|
21
|
+
id: 'repository',
|
|
22
|
+
file: 'repository.hbs',
|
|
23
|
+
required: false,
|
|
24
|
+
condition: (a) => !!a.components?.length,
|
|
25
|
+
tokenEstimate: 300
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'architecture',
|
|
29
|
+
file: 'architecture.hbs',
|
|
30
|
+
required: false,
|
|
31
|
+
condition: (analysis) => !!analysis.infrastructure?.iac || analysis.components?.length > 3,
|
|
32
|
+
tokenEstimate: 400
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'components',
|
|
36
|
+
file: 'components.hbs',
|
|
37
|
+
required: false,
|
|
38
|
+
condition: (a) => (a.components?.length || 0) > 0,
|
|
39
|
+
tokenEstimate: 300
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'auth',
|
|
43
|
+
file: 'auth.hbs',
|
|
44
|
+
required: false,
|
|
45
|
+
condition: (a) => !!a.authentication,
|
|
46
|
+
tokenEstimate: 200
|
|
47
|
+
},
|
|
48
|
+
{ id: 'quick-reference', file: 'quick-reference.hbs', required: false, tokenEstimate: 250 },
|
|
49
|
+
{
|
|
50
|
+
id: 'skills-droids',
|
|
51
|
+
file: 'skills-droids.hbs',
|
|
52
|
+
required: false,
|
|
53
|
+
condition: () => existsSync(join(process.cwd(), '.factory/skills')) || existsSync(join(process.cwd(), '.factory/droids')),
|
|
54
|
+
tokenEstimate: 400
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'infrastructure',
|
|
58
|
+
file: 'infrastructure.hbs',
|
|
59
|
+
required: false,
|
|
60
|
+
condition: (analysis) => (analysis.directories?.infrastructure?.length || 0) > 0,
|
|
61
|
+
tokenEstimate: 300
|
|
62
|
+
},
|
|
63
|
+
{ id: 'testing', file: 'testing.hbs', required: false, tokenEstimate: 150 },
|
|
64
|
+
{
|
|
65
|
+
id: 'troubleshooting',
|
|
66
|
+
file: 'troubleshooting.hbs',
|
|
67
|
+
required: false,
|
|
68
|
+
condition: () => false, // Only include if explicitly requested
|
|
69
|
+
tokenEstimate: 300
|
|
70
|
+
},
|
|
71
|
+
{ id: 'config-files', file: 'config-files.hbs', required: false, tokenEstimate: 200 },
|
|
72
|
+
{ id: 'checklist', file: 'checklist.hbs', required: true, tokenEstimate: 100 },
|
|
73
|
+
{
|
|
74
|
+
id: 'knowledge',
|
|
75
|
+
file: 'knowledge.hbs',
|
|
76
|
+
required: false,
|
|
77
|
+
condition: () => false, // Only include if memory has content
|
|
78
|
+
tokenEstimate: 400
|
|
79
|
+
},
|
|
80
|
+
{ id: 'footer', file: 'footer.hbs', required: true, tokenEstimate: 20 },
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Modular template loader with lazy-loading support.
|
|
84
|
+
*/
|
|
85
|
+
export class TemplateLoader {
|
|
86
|
+
sectionsDir;
|
|
87
|
+
maxTokens;
|
|
88
|
+
sections;
|
|
89
|
+
compiledSections;
|
|
90
|
+
analysis = null;
|
|
91
|
+
constructor(config = {}) {
|
|
92
|
+
this.sectionsDir = config.sectionsDir || this.findSectionsDir();
|
|
93
|
+
this.maxTokens = config.maxTokens || 8000; // Conservative default
|
|
94
|
+
this.sections = [...DEFAULT_SECTIONS];
|
|
95
|
+
this.compiledSections = new Map();
|
|
96
|
+
// Apply include/exclude filters
|
|
97
|
+
if (config.includeSections) {
|
|
98
|
+
this.sections = this.sections.filter(s => s.required || config.includeSections.includes(s.id));
|
|
99
|
+
}
|
|
100
|
+
if (config.excludeSections) {
|
|
101
|
+
this.sections = this.sections.filter(s => s.required || !config.excludeSections.includes(s.id));
|
|
102
|
+
}
|
|
103
|
+
if (config.forceInclude) {
|
|
104
|
+
for (const id of config.forceInclude) {
|
|
105
|
+
const existing = this.sections.find(s => s.id === id);
|
|
106
|
+
if (existing) {
|
|
107
|
+
existing.required = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.registerHelpers();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Find the sections directory.
|
|
115
|
+
*/
|
|
116
|
+
findSectionsDir() {
|
|
117
|
+
const locations = [
|
|
118
|
+
join(process.cwd(), 'templates/sections'),
|
|
119
|
+
join(__dirname, '../../templates/sections'),
|
|
120
|
+
];
|
|
121
|
+
for (const loc of locations) {
|
|
122
|
+
if (existsSync(loc)) {
|
|
123
|
+
return loc;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Fall back to main template if no sections exist
|
|
127
|
+
return join(__dirname, '../../templates');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Register Handlebars helpers.
|
|
131
|
+
*/
|
|
132
|
+
registerHelpers() {
|
|
133
|
+
// Conditional section helper
|
|
134
|
+
Handlebars.registerHelper('section', (sectionId, options) => {
|
|
135
|
+
const section = this.sections.find(s => s.id === sectionId);
|
|
136
|
+
if (!section)
|
|
137
|
+
return '';
|
|
138
|
+
if (!this.shouldIncludeSection(section)) {
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
return options.fn(this);
|
|
142
|
+
});
|
|
143
|
+
// Token budget helper
|
|
144
|
+
Handlebars.registerHelper('withinBudget', (tokens, options) => {
|
|
145
|
+
if (this.getRemainingTokenBudget() >= tokens) {
|
|
146
|
+
return options.fn(this);
|
|
147
|
+
}
|
|
148
|
+
return options.inverse(this);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Set the project analysis for conditional loading.
|
|
153
|
+
*/
|
|
154
|
+
setAnalysis(analysis) {
|
|
155
|
+
this.analysis = analysis;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if a section should be included based on conditions.
|
|
159
|
+
*/
|
|
160
|
+
shouldIncludeSection(section) {
|
|
161
|
+
if (section.required)
|
|
162
|
+
return true;
|
|
163
|
+
if (section.condition && this.analysis) {
|
|
164
|
+
return section.condition(this.analysis);
|
|
165
|
+
}
|
|
166
|
+
return true; // Include by default if no condition
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get sections that should be included.
|
|
170
|
+
*/
|
|
171
|
+
getIncludedSections() {
|
|
172
|
+
return this.sections.filter(s => this.shouldIncludeSection(s));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Estimate total tokens for included sections.
|
|
176
|
+
*/
|
|
177
|
+
estimateTotalTokens() {
|
|
178
|
+
return this.getIncludedSections()
|
|
179
|
+
.reduce((sum, s) => sum + s.tokenEstimate, 0);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get remaining token budget.
|
|
183
|
+
*/
|
|
184
|
+
getRemainingTokenBudget() {
|
|
185
|
+
return this.maxTokens - this.estimateTotalTokens();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Load and compile a section template.
|
|
189
|
+
*/
|
|
190
|
+
loadSection(sectionId) {
|
|
191
|
+
if (this.compiledSections.has(sectionId)) {
|
|
192
|
+
return this.compiledSections.get(sectionId);
|
|
193
|
+
}
|
|
194
|
+
const section = this.sections.find(s => s.id === sectionId);
|
|
195
|
+
if (!section)
|
|
196
|
+
return null;
|
|
197
|
+
const filePath = join(this.sectionsDir, section.file);
|
|
198
|
+
if (!existsSync(filePath)) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
203
|
+
const compiled = Handlebars.compile(content);
|
|
204
|
+
this.compiledSections.set(sectionId, compiled);
|
|
205
|
+
return compiled;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Load all sections and assemble the full template.
|
|
213
|
+
*/
|
|
214
|
+
loadFullTemplate() {
|
|
215
|
+
// Check if sections directory exists
|
|
216
|
+
if (!existsSync(this.sectionsDir) || !this.hasSectionFiles()) {
|
|
217
|
+
// Fall back to monolithic template
|
|
218
|
+
return this.loadMonolithicTemplate();
|
|
219
|
+
}
|
|
220
|
+
const parts = [];
|
|
221
|
+
for (const section of this.getIncludedSections()) {
|
|
222
|
+
const filePath = join(this.sectionsDir, section.file);
|
|
223
|
+
if (existsSync(filePath)) {
|
|
224
|
+
parts.push(readFileSync(filePath, 'utf-8'));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return parts.join('\n\n');
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check if section files exist.
|
|
231
|
+
*/
|
|
232
|
+
hasSectionFiles() {
|
|
233
|
+
try {
|
|
234
|
+
const files = readdirSync(this.sectionsDir);
|
|
235
|
+
return files.some(f => f.endsWith('.hbs'));
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Load the monolithic template as fallback.
|
|
243
|
+
*/
|
|
244
|
+
loadMonolithicTemplate() {
|
|
245
|
+
const locations = [
|
|
246
|
+
join(process.cwd(), 'templates/CLAUDE.template.md'),
|
|
247
|
+
join(__dirname, '../../templates/CLAUDE.template.md'),
|
|
248
|
+
];
|
|
249
|
+
for (const loc of locations) {
|
|
250
|
+
if (existsSync(loc)) {
|
|
251
|
+
return readFileSync(loc, 'utf-8');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
throw new Error('No template found');
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Compile the full template with context.
|
|
258
|
+
*/
|
|
259
|
+
compile(context) {
|
|
260
|
+
const template = this.loadFullTemplate();
|
|
261
|
+
const compiled = Handlebars.compile(template);
|
|
262
|
+
return compiled(context);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get a summary of what will be included.
|
|
266
|
+
*/
|
|
267
|
+
getSummary() {
|
|
268
|
+
const included = this.getIncludedSections().map(s => s.id);
|
|
269
|
+
const excluded = this.sections
|
|
270
|
+
.filter(s => !this.shouldIncludeSection(s))
|
|
271
|
+
.map(s => s.id);
|
|
272
|
+
const estimatedTokens = this.estimateTotalTokens();
|
|
273
|
+
return {
|
|
274
|
+
includedSections: included,
|
|
275
|
+
excludedSections: excluded,
|
|
276
|
+
estimatedTokens,
|
|
277
|
+
withinBudget: estimatedTokens <= this.maxTokens,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Create section template files from the monolithic template.
|
|
283
|
+
* This is a one-time migration utility.
|
|
284
|
+
*/
|
|
285
|
+
export async function splitTemplateIntoSections(templatePath, outputDir) {
|
|
286
|
+
// This would be implemented to parse the monolithic template
|
|
287
|
+
// and split it into section files based on markers.
|
|
288
|
+
// For now, we use the monolithic template directly.
|
|
289
|
+
console.log(`Would split ${templatePath} into sections at ${outputDir}`);
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=template-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-loader.js","sourceRoot":"","sources":["../../src/generators/template-loader.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,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mBAAmB,EAAE,CAAC;QAEnD,OAAO;YACL,gBAAgB,EAAE,QAAQ;YAC1B,gBAAgB,EAAE,QAAQ;YAC1B,eAAe;YACf,YAAY,EAAE,eAAe,IAAI,IAAI,CAAC,SAAS;SAChD,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,YAAoB,EACpB,SAAiB;IAEjB,6DAA6D;IAC7D,oDAAoD;IACpD,oDAAoD;IACpD,OAAO,CAAC,GAAG,CAAC,eAAe,YAAY,qBAAqB,SAAS,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { QdrantServerlessConfig } from '../types/config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serverless Qdrant manager for cost-optimized vector storage.
|
|
4
|
+
* Supports lazy-start local Docker instances and cloud serverless backends.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ServerlessQdrantManager {
|
|
7
|
+
private config;
|
|
8
|
+
private lastActivityTime;
|
|
9
|
+
private healthCheckInterval;
|
|
10
|
+
private idleCheckInterval;
|
|
11
|
+
private isStarting;
|
|
12
|
+
private inMemoryFallback;
|
|
13
|
+
constructor(config: QdrantServerlessConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Normalize and fill in default config values.
|
|
16
|
+
*/
|
|
17
|
+
private normalizeConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Get the current environment (dev/prod).
|
|
20
|
+
*/
|
|
21
|
+
private getEnvironment;
|
|
22
|
+
/**
|
|
23
|
+
* Get the effective backend based on mode and environment.
|
|
24
|
+
*/
|
|
25
|
+
getEffectiveBackend(): 'local' | 'cloud' | 'memory';
|
|
26
|
+
/**
|
|
27
|
+
* Get the Qdrant endpoint URL.
|
|
28
|
+
*/
|
|
29
|
+
getEndpoint(): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the API key for cloud backend.
|
|
32
|
+
*/
|
|
33
|
+
getApiKey(): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Check if local Qdrant is running.
|
|
36
|
+
*/
|
|
37
|
+
private isLocalRunning;
|
|
38
|
+
/**
|
|
39
|
+
* Start local Qdrant Docker container.
|
|
40
|
+
*/
|
|
41
|
+
private startLocal;
|
|
42
|
+
/**
|
|
43
|
+
* Stop local Qdrant Docker container.
|
|
44
|
+
*/
|
|
45
|
+
private stopLocal;
|
|
46
|
+
/**
|
|
47
|
+
* Ensure local Qdrant is running, starting it if needed.
|
|
48
|
+
*/
|
|
49
|
+
ensureLocalRunning(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Record activity to reset idle timer.
|
|
52
|
+
*/
|
|
53
|
+
recordActivity(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Start health check and idle monitoring.
|
|
56
|
+
*/
|
|
57
|
+
private startMonitoring;
|
|
58
|
+
/**
|
|
59
|
+
* Stop monitoring intervals.
|
|
60
|
+
*/
|
|
61
|
+
private stopMonitoring;
|
|
62
|
+
/**
|
|
63
|
+
* Store vectors with automatic backend selection.
|
|
64
|
+
*/
|
|
65
|
+
store(collection: string, vectors: Array<{
|
|
66
|
+
id: string;
|
|
67
|
+
vector: number[];
|
|
68
|
+
payload: Record<string, unknown>;
|
|
69
|
+
}>): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Search vectors with automatic backend selection.
|
|
72
|
+
*/
|
|
73
|
+
search(collection: string, vector: number[], limit?: number): Promise<Array<{
|
|
74
|
+
id: string;
|
|
75
|
+
score: number;
|
|
76
|
+
payload: Record<string, unknown>;
|
|
77
|
+
}>>;
|
|
78
|
+
/**
|
|
79
|
+
* Simple in-memory cosine similarity search (fallback).
|
|
80
|
+
*/
|
|
81
|
+
private inMemorySearch;
|
|
82
|
+
/**
|
|
83
|
+
* Calculate cosine similarity between two vectors.
|
|
84
|
+
*/
|
|
85
|
+
private cosineSimilarity;
|
|
86
|
+
/**
|
|
87
|
+
* Gracefully shutdown the manager.
|
|
88
|
+
*/
|
|
89
|
+
shutdown(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get current status.
|
|
92
|
+
*/
|
|
93
|
+
getStatus(): {
|
|
94
|
+
backend: 'local' | 'cloud' | 'memory';
|
|
95
|
+
localRunning: boolean;
|
|
96
|
+
lastActivity: number;
|
|
97
|
+
inMemorySize: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export declare function getServerlessQdrantManager(config?: QdrantServerlessConfig): ServerlessQdrantManager;
|
|
101
|
+
export declare function initServerlessQdrant(config: QdrantServerlessConfig): ServerlessQdrantManager;
|
|
102
|
+
//# sourceMappingURL=serverless-qdrant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverless-qdrant.d.ts","sourceRoot":"","sources":["../../src/memory/serverless-qdrant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,mBAAmB,CAA+B;IAC1D,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAAqC;gBAEjD,MAAM,EAAE,sBAAsB;IAI1C;;OAEG;IACH,OAAO,CAAC,eAAe;IA8BvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,mBAAmB,IAAI,OAAO,GAAG,OAAO,GAAG,QAAQ;IAwBnD;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAmBpC;;OAEG;IACH,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;YACW,UAAU;IAuDxB;;OAEG;YACW,SAAS;IAUvB;;OAEG;IACG,kBAAkB,IAAI,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