@eddacraft/anvil-adapters 0.1.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/AGENTS.md +180 -0
- package/BMAD_ADAPTER_SPEC.md +489 -0
- package/LICENSE +14 -0
- package/README.md +500 -0
- package/dist/aps-markdown/adapter.d.ts +102 -0
- package/dist/aps-markdown/adapter.d.ts.map +1 -0
- package/dist/aps-markdown/adapter.js +351 -0
- package/dist/aps-markdown/index.d.ts +8 -0
- package/dist/aps-markdown/index.d.ts.map +1 -0
- package/dist/aps-markdown/index.js +7 -0
- package/dist/base/file-discovery.d.ts +63 -0
- package/dist/base/file-discovery.d.ts.map +1 -0
- package/dist/base/file-discovery.js +246 -0
- package/dist/base/index.d.ts +10 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +9 -0
- package/dist/base/registry.d.ts +155 -0
- package/dist/base/registry.d.ts.map +1 -0
- package/dist/base/registry.js +227 -0
- package/dist/base/testing.d.ts +102 -0
- package/dist/base/testing.d.ts.map +1 -0
- package/dist/base/testing.js +221 -0
- package/dist/base/types.d.ts +255 -0
- package/dist/base/types.d.ts.map +1 -0
- package/dist/base/types.js +78 -0
- package/dist/base/utils.d.ts +127 -0
- package/dist/base/utils.d.ts.map +1 -0
- package/dist/base/utils.js +254 -0
- package/dist/bmad/format-adapter.d.ts +76 -0
- package/dist/bmad/format-adapter.d.ts.map +1 -0
- package/dist/bmad/format-adapter.js +186 -0
- package/dist/bmad/index.d.ts +12 -0
- package/dist/bmad/index.d.ts.map +1 -0
- package/dist/bmad/index.js +10 -0
- package/dist/bmad/parser.d.ts +12 -0
- package/dist/bmad/parser.d.ts.map +1 -0
- package/dist/bmad/parser.js +181 -0
- package/dist/bmad/serializer.d.ts +16 -0
- package/dist/bmad/serializer.d.ts.map +1 -0
- package/dist/bmad/serializer.js +170 -0
- package/dist/bmad/types.d.ts +127 -0
- package/dist/bmad/types.d.ts.map +1 -0
- package/dist/bmad/types.js +47 -0
- package/dist/bmad/utils.d.ts +120 -0
- package/dist/bmad/utils.d.ts.map +1 -0
- package/dist/bmad/utils.js +480 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +2 -0
- package/dist/common/registry.d.ts +18 -0
- package/dist/common/registry.d.ts.map +1 -0
- package/dist/common/registry.js +58 -0
- package/dist/common/types.d.ts +68 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +12 -0
- package/dist/generic/format-adapter.d.ts +64 -0
- package/dist/generic/format-adapter.d.ts.map +1 -0
- package/dist/generic/format-adapter.js +159 -0
- package/dist/generic/index.d.ts +10 -0
- package/dist/generic/index.d.ts.map +1 -0
- package/dist/generic/index.js +9 -0
- package/dist/generic/parser.d.ts +11 -0
- package/dist/generic/parser.d.ts.map +1 -0
- package/dist/generic/parser.js +106 -0
- package/dist/generic/serializer.d.ts +11 -0
- package/dist/generic/serializer.d.ts.map +1 -0
- package/dist/generic/serializer.js +118 -0
- package/dist/generic/types.d.ts +52 -0
- package/dist/generic/types.d.ts.map +1 -0
- package/dist/generic/types.js +6 -0
- package/dist/generic/utils.d.ts +51 -0
- package/dist/generic/utils.d.ts.map +1 -0
- package/dist/generic/utils.js +232 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/speckit/export.d.ts +22 -0
- package/dist/speckit/export.d.ts.map +1 -0
- package/dist/speckit/export.js +384 -0
- package/dist/speckit/format-adapter.d.ts +104 -0
- package/dist/speckit/format-adapter.d.ts.map +1 -0
- package/dist/speckit/format-adapter.js +488 -0
- package/dist/speckit/import-v2.d.ts +33 -0
- package/dist/speckit/import-v2.d.ts.map +1 -0
- package/dist/speckit/import-v2.js +361 -0
- package/dist/speckit/import.d.ts +16 -0
- package/dist/speckit/import.d.ts.map +1 -0
- package/dist/speckit/import.js +247 -0
- package/dist/speckit/index.d.ts +5 -0
- package/dist/speckit/index.d.ts.map +1 -0
- package/dist/speckit/index.js +4 -0
- package/dist/speckit/parser.d.ts +28 -0
- package/dist/speckit/parser.d.ts.map +1 -0
- package/dist/speckit/parser.js +283 -0
- package/dist/speckit/parsers/plan-parser.d.ts +71 -0
- package/dist/speckit/parsers/plan-parser.d.ts.map +1 -0
- package/dist/speckit/parsers/plan-parser.js +216 -0
- package/dist/speckit/parsers/spec-parser.d.ts +67 -0
- package/dist/speckit/parsers/spec-parser.d.ts.map +1 -0
- package/dist/speckit/parsers/spec-parser.js +255 -0
- package/dist/speckit/parsers/tasks-parser.d.ts +57 -0
- package/dist/speckit/parsers/tasks-parser.d.ts.map +1 -0
- package/dist/speckit/parsers/tasks-parser.js +157 -0
- package/package.json +23 -0
- package/project.json +29 -0
- package/src/__tests__/adapter-edge-cases.test.ts +937 -0
- package/src/__tests__/bmad-format-adapter.test.ts +1470 -0
- package/src/__tests__/fixtures/aps/expected-output.json +83 -0
- package/src/__tests__/fixtures/bmad/invalid-malformed-yaml.md +16 -0
- package/src/__tests__/fixtures/bmad/invalid-no-requirements.md +23 -0
- package/src/__tests__/fixtures/bmad/invalid-only-yaml.md +16 -0
- package/src/__tests__/fixtures/bmad/invalid-too-short.md +3 -0
- package/src/__tests__/fixtures/bmad/invalid-wrong-format.md +40 -0
- package/src/__tests__/fixtures/bmad/valid-agent.md +27 -0
- package/src/__tests__/fixtures/bmad/valid-architecture.md +116 -0
- package/src/__tests__/fixtures/bmad/valid-complex-prd.md +161 -0
- package/src/__tests__/fixtures/bmad/valid-epic.md +73 -0
- package/src/__tests__/fixtures/bmad/valid-minimal-prd.md +19 -0
- package/src/__tests__/fixtures/bmad/valid-prd.md +107 -0
- package/src/__tests__/fixtures/bmad/valid-story.md +107 -0
- package/src/__tests__/fixtures/bmad/valid-task.md +79 -0
- package/src/__tests__/fixtures/bmad/valid-v6-prd.md +35 -0
- package/src/__tests__/fixtures/generic/plan-detailed.md +39 -0
- package/src/__tests__/fixtures/generic/prd-simple.md +27 -0
- package/src/__tests__/fixtures/generic/rfc-example.md +26 -0
- package/src/__tests__/fixtures/generic/todo-list.md +23 -0
- package/src/__tests__/fixtures/speckit/sample-plan.md +63 -0
- package/src/__tests__/fixtures/speckit/sample-spec-namespaced.md +50 -0
- package/src/__tests__/fixtures/speckit/sample-spec.md +105 -0
- package/src/__tests__/fixtures/speckit/sample-tasks.md +87 -0
- package/src/__tests__/fixtures/speckit-official/auth-feature/plan.md +272 -0
- package/src/__tests__/fixtures/speckit-official/auth-feature/spec.md +149 -0
- package/src/__tests__/fixtures/speckit-official/auth-feature/tasks.md +169 -0
- package/src/__tests__/generic-format-adapter.test.ts +398 -0
- package/src/__tests__/speckit-export.test.ts +233 -0
- package/src/__tests__/speckit-format-adapter.test.ts +832 -0
- package/src/__tests__/speckit-import-v2.test.ts +253 -0
- package/src/__tests__/speckit-import.test.ts +209 -0
- package/src/__tests__/speckit-parser.test.ts +219 -0
- package/src/__tests__/speckit-spec-parser.test.ts +120 -0
- package/src/aps-markdown/__tests__/__fixtures__/simple-leaf.aps.md +17 -0
- package/src/aps-markdown/__tests__/adapter.test.ts +393 -0
- package/src/aps-markdown/adapter.ts +455 -0
- package/src/aps-markdown/index.ts +8 -0
- package/src/base/__tests__/registry.test.ts +515 -0
- package/src/base/file-discovery.ts +305 -0
- package/src/base/index.ts +10 -0
- package/src/base/registry.ts +263 -0
- package/src/base/testing.ts +334 -0
- package/src/base/types.ts +342 -0
- package/src/base/utils.ts +306 -0
- package/src/bmad/format-adapter.ts +227 -0
- package/src/bmad/index.ts +21 -0
- package/src/bmad/parser.ts +224 -0
- package/src/bmad/serializer.ts +206 -0
- package/src/bmad/types.ts +135 -0
- package/src/bmad/utils.ts +575 -0
- package/src/common/index.ts +2 -0
- package/src/common/registry.ts +72 -0
- package/src/common/types.ts +84 -0
- package/src/generic/__tests__/serializer.test.ts +167 -0
- package/src/generic/format-adapter.ts +200 -0
- package/src/generic/index.ts +11 -0
- package/src/generic/parser.ts +129 -0
- package/src/generic/serializer.ts +134 -0
- package/src/generic/types.ts +53 -0
- package/src/generic/utils.ts +270 -0
- package/src/index.ts +48 -0
- package/src/speckit/export.ts +489 -0
- package/src/speckit/format-adapter.ts +595 -0
- package/src/speckit/import-v2.ts +445 -0
- package/src/speckit/import.ts +305 -0
- package/src/speckit/index.ts +4 -0
- package/src/speckit/parser.ts +351 -0
- package/src/speckit/parsers/plan-parser.ts +342 -0
- package/src/speckit/parsers/spec-parser.ts +379 -0
- package/src/speckit/parsers/tasks-parser.ts +246 -0
- package/tsconfig.json +26 -0
- package/tsconfig.lib.json +21 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/tsconfig.spec.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Testing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helpers for testing format adapters with common patterns and assertions.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Test helper for adapter detection
|
|
8
|
+
*/
|
|
9
|
+
export class AdapterTester {
|
|
10
|
+
adapter;
|
|
11
|
+
constructor(adapter) {
|
|
12
|
+
this.adapter = adapter;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Test detection with a fixture
|
|
16
|
+
*/
|
|
17
|
+
testDetection(fixture) {
|
|
18
|
+
const result = this.adapter.detect(fixture.content);
|
|
19
|
+
if (fixture.expectedDetection) {
|
|
20
|
+
if (fixture.expectedDetection.detected !== undefined) {
|
|
21
|
+
if (result.detected !== fixture.expectedDetection.detected) {
|
|
22
|
+
throw new Error(`Detection mismatch for "${fixture.name}": expected ${fixture.expectedDetection.detected}, got ${result.detected}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (fixture.expectedDetection.confidence !== undefined) {
|
|
26
|
+
if (result.confidence < fixture.expectedDetection.confidence) {
|
|
27
|
+
throw new Error(`Confidence too low for "${fixture.name}": expected >=${fixture.expectedDetection.confidence}, got ${result.confidence}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Test parsing with a fixture
|
|
35
|
+
*/
|
|
36
|
+
async testParse(fixture) {
|
|
37
|
+
const result = await this.adapter.parse(fixture.content, fixture.parseContext, fixture.options);
|
|
38
|
+
if (fixture.expectParseSuccess !== undefined) {
|
|
39
|
+
if (result.success !== fixture.expectParseSuccess) {
|
|
40
|
+
throw new Error(`Parse success mismatch for "${fixture.name}": expected ${fixture.expectParseSuccess}, got ${result.success}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (fixture.expectedErrors && fixture.expectedErrors.length > 0) {
|
|
44
|
+
if (!result.errors || result.errors.length === 0) {
|
|
45
|
+
throw new Error(`Expected errors for "${fixture.name}" but got none`);
|
|
46
|
+
}
|
|
47
|
+
const errorCodes = result.errors.map((e) => e.code);
|
|
48
|
+
for (const expectedCode of fixture.expectedErrors) {
|
|
49
|
+
if (!errorCodes.includes(expectedCode)) {
|
|
50
|
+
throw new Error(`Expected error code "${expectedCode}" for "${fixture.name}" but found: ${errorCodes.join(', ')}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (fixture.expectedWarnings && fixture.expectedWarnings.length > 0) {
|
|
55
|
+
if (!result.warnings || result.warnings.length === 0) {
|
|
56
|
+
throw new Error(`Expected warnings for "${fixture.name}" but got none`);
|
|
57
|
+
}
|
|
58
|
+
const warningCodes = result.warnings.map((w) => w.code);
|
|
59
|
+
for (const expectedCode of fixture.expectedWarnings) {
|
|
60
|
+
if (!warningCodes.includes(expectedCode)) {
|
|
61
|
+
throw new Error(`Expected warning code "${expectedCode}" for "${fixture.name}" but found: ${warningCodes.join(', ')}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (fixture.expectedPlan && result.data) {
|
|
66
|
+
this.assertPlanMatches(result.data, fixture.expectedPlan, fixture.name);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Test serialization
|
|
72
|
+
*/
|
|
73
|
+
async testSerialize(plan, options) {
|
|
74
|
+
return this.adapter.serialize(plan, options);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Test round-trip: parse then serialize then parse again
|
|
78
|
+
*/
|
|
79
|
+
async testRoundTrip(fixture) {
|
|
80
|
+
// First parse
|
|
81
|
+
const firstParse = await this.adapter.parse(fixture.content, fixture.parseContext, fixture.options);
|
|
82
|
+
if (!firstParse.success || !firstParse.data) {
|
|
83
|
+
throw new Error(`First parse failed for "${fixture.name}"`);
|
|
84
|
+
}
|
|
85
|
+
// Serialize
|
|
86
|
+
const serialized = await this.adapter.serialize(firstParse.data, fixture.options);
|
|
87
|
+
if (!serialized.success || !serialized.content) {
|
|
88
|
+
throw new Error(`Serialization failed for "${fixture.name}"`);
|
|
89
|
+
}
|
|
90
|
+
// Second parse
|
|
91
|
+
const secondParse = await this.adapter.parse(serialized.content, fixture.parseContext, fixture.options);
|
|
92
|
+
if (!secondParse.success || !secondParse.data) {
|
|
93
|
+
throw new Error(`Second parse failed for "${fixture.name}"`);
|
|
94
|
+
}
|
|
95
|
+
// Compare plans
|
|
96
|
+
const planMatches = this.plansEqual(firstParse.data, secondParse.data);
|
|
97
|
+
return {
|
|
98
|
+
firstParse,
|
|
99
|
+
serialized,
|
|
100
|
+
secondParse,
|
|
101
|
+
planMatches,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Assert that parsed plan matches expected values
|
|
106
|
+
*/
|
|
107
|
+
assertPlanMatches(actual, expected, testName) {
|
|
108
|
+
if (expected.intent !== undefined && actual.intent !== expected.intent) {
|
|
109
|
+
throw new Error(`Intent mismatch for "${testName}": expected "${expected.intent}", got "${actual.intent}"`);
|
|
110
|
+
}
|
|
111
|
+
if (expected.id !== undefined && actual.id !== expected.id) {
|
|
112
|
+
throw new Error(`ID mismatch for "${testName}": expected "${expected.id}", got "${actual.id}"`);
|
|
113
|
+
}
|
|
114
|
+
if (expected.proposed_changes !== undefined &&
|
|
115
|
+
actual.proposed_changes.length !== expected.proposed_changes.length) {
|
|
116
|
+
throw new Error(`Changes count mismatch for "${testName}": expected ${expected.proposed_changes.length}, got ${actual.proposed_changes.length}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Compare two plans for equality (ignoring hash and timestamps)
|
|
121
|
+
*/
|
|
122
|
+
plansEqual(plan1, plan2) {
|
|
123
|
+
// Compare intents
|
|
124
|
+
if (plan1.intent !== plan2.intent)
|
|
125
|
+
return false;
|
|
126
|
+
// Compare changes count
|
|
127
|
+
if (plan1.proposed_changes.length !== plan2.proposed_changes.length)
|
|
128
|
+
return false;
|
|
129
|
+
// Compare each change
|
|
130
|
+
for (let i = 0; i < plan1.proposed_changes.length; i++) {
|
|
131
|
+
const change1 = plan1.proposed_changes[i];
|
|
132
|
+
const change2 = plan2.proposed_changes[i];
|
|
133
|
+
if (change1.type !== change2.type)
|
|
134
|
+
return false;
|
|
135
|
+
if (change1.path !== change2.path)
|
|
136
|
+
return false;
|
|
137
|
+
if (change1.description !== change2.description)
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a test adapter tester
|
|
145
|
+
*/
|
|
146
|
+
export function createTester(adapter) {
|
|
147
|
+
return new AdapterTester(adapter);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create a basic parse context for testing
|
|
151
|
+
*/
|
|
152
|
+
export function createTestContext(overrides) {
|
|
153
|
+
return {
|
|
154
|
+
author: 'test-user',
|
|
155
|
+
repositoryPath: '/test/repo',
|
|
156
|
+
branch: 'main',
|
|
157
|
+
commit: 'abc123',
|
|
158
|
+
timestamp: '2024-01-01T00:00:00.000Z',
|
|
159
|
+
...overrides,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create basic adapter options for testing
|
|
164
|
+
*/
|
|
165
|
+
export function createTestOptions(overrides) {
|
|
166
|
+
return {
|
|
167
|
+
preserveComments: true,
|
|
168
|
+
preserveMetadata: true,
|
|
169
|
+
strict: false,
|
|
170
|
+
...overrides,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Assert detection result
|
|
175
|
+
*/
|
|
176
|
+
export function assertDetection(result, expected) {
|
|
177
|
+
if (result.detected !== expected.detected) {
|
|
178
|
+
throw new Error(`Detection mismatch: expected ${expected.detected}, got ${result.detected}. Reason: ${result.reason}`);
|
|
179
|
+
}
|
|
180
|
+
if (expected.minConfidence !== undefined && result.confidence < expected.minConfidence) {
|
|
181
|
+
throw new Error(`Confidence too low: expected >=${expected.minConfidence}, got ${result.confidence}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Assert parse success
|
|
186
|
+
*/
|
|
187
|
+
export function assertParseSuccess(result) {
|
|
188
|
+
if (!result.success) {
|
|
189
|
+
const errorMsg = result.errors?.map((e) => `${e.code}: ${e.message}`).join(', ') || 'Unknown error';
|
|
190
|
+
throw new Error(`Parse failed: ${errorMsg}`);
|
|
191
|
+
}
|
|
192
|
+
if (!result.data) {
|
|
193
|
+
throw new Error('Parse succeeded but no data returned');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Assert parse failure
|
|
198
|
+
*/
|
|
199
|
+
export function assertParseFailure(result, expectedErrorCode) {
|
|
200
|
+
if (result.success) {
|
|
201
|
+
throw new Error('Expected parse to fail but it succeeded');
|
|
202
|
+
}
|
|
203
|
+
if (expectedErrorCode && result.errors) {
|
|
204
|
+
const errorCodes = result.errors.map((e) => e.code);
|
|
205
|
+
if (!errorCodes.includes(expectedErrorCode)) {
|
|
206
|
+
throw new Error(`Expected error code "${expectedErrorCode}" but found: ${errorCodes.join(', ')}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Assert serialize success
|
|
212
|
+
*/
|
|
213
|
+
export function assertSerializeSuccess(result) {
|
|
214
|
+
if (!result.success) {
|
|
215
|
+
const errorMsg = result.errors?.map((e) => `${e.code}: ${e.message}`).join(', ') || 'Unknown error';
|
|
216
|
+
throw new Error(`Serialize failed: ${errorMsg}`);
|
|
217
|
+
}
|
|
218
|
+
if (!result.content) {
|
|
219
|
+
throw new Error('Serialize succeeded but no content returned');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Adapter Framework Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the core interfaces for format adapters that convert between
|
|
5
|
+
* external planning formats (SpecKit, BMAD, etc.) and APS.
|
|
6
|
+
*/
|
|
7
|
+
import type { APSPlan, ValidationResult } from '@eddacraft/anvil-core';
|
|
8
|
+
/**
|
|
9
|
+
* Result of format detection
|
|
10
|
+
*/
|
|
11
|
+
export interface DetectionResult {
|
|
12
|
+
/** Whether this adapter can handle the content */
|
|
13
|
+
detected: boolean;
|
|
14
|
+
/** Confidence score (0-100) */
|
|
15
|
+
confidence: number;
|
|
16
|
+
/** Reason for detection result */
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Result of parsing external format to APS
|
|
21
|
+
*/
|
|
22
|
+
export interface ParseResult {
|
|
23
|
+
/** Whether parsing succeeded */
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** Parsed APS plan (if successful) */
|
|
26
|
+
data?: APSPlan;
|
|
27
|
+
/** Errors encountered during parsing */
|
|
28
|
+
errors?: AdapterError[];
|
|
29
|
+
/** Non-fatal warnings */
|
|
30
|
+
warnings?: AdapterWarning[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of serializing APS to external format
|
|
34
|
+
*/
|
|
35
|
+
export interface SerializeResult {
|
|
36
|
+
/** Whether serialization succeeded */
|
|
37
|
+
success: boolean;
|
|
38
|
+
/** Serialized content (if successful) */
|
|
39
|
+
content?: string;
|
|
40
|
+
/** Errors encountered during serialization */
|
|
41
|
+
errors?: AdapterError[];
|
|
42
|
+
/** Non-fatal warnings */
|
|
43
|
+
warnings?: AdapterWarning[];
|
|
44
|
+
/** Additional metadata about serialization */
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Error encountered during adapter operation
|
|
49
|
+
*/
|
|
50
|
+
export interface AdapterError {
|
|
51
|
+
/** Error code for programmatic handling */
|
|
52
|
+
code: string;
|
|
53
|
+
/** Human-readable error message */
|
|
54
|
+
message: string;
|
|
55
|
+
/** Path to the problematic element (e.g., "changes[0].path") */
|
|
56
|
+
path?: string;
|
|
57
|
+
/** Line number in source content (if applicable) */
|
|
58
|
+
line?: number;
|
|
59
|
+
/** Column number in source content (if applicable) */
|
|
60
|
+
column?: number;
|
|
61
|
+
/** Additional error details */
|
|
62
|
+
details?: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Warning encountered during adapter operation
|
|
66
|
+
*/
|
|
67
|
+
export interface AdapterWarning {
|
|
68
|
+
/** Warning code for programmatic handling */
|
|
69
|
+
code: string;
|
|
70
|
+
/** Human-readable warning message */
|
|
71
|
+
message: string;
|
|
72
|
+
/** Path to the element (e.g., "changes[0].description") */
|
|
73
|
+
path?: string;
|
|
74
|
+
/** Line number in source content (if applicable) */
|
|
75
|
+
line?: number;
|
|
76
|
+
/** Column number in source content (if applicable) */
|
|
77
|
+
column?: number;
|
|
78
|
+
/** Additional warning details */
|
|
79
|
+
details?: unknown;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Context provided when parsing external formats
|
|
83
|
+
*/
|
|
84
|
+
export interface ParseContext {
|
|
85
|
+
/** Repository path or URL */
|
|
86
|
+
repositoryPath?: string;
|
|
87
|
+
/** Git branch */
|
|
88
|
+
branch?: string;
|
|
89
|
+
/** Git commit hash */
|
|
90
|
+
commit?: string;
|
|
91
|
+
/** Author information */
|
|
92
|
+
author?: string;
|
|
93
|
+
/** Timestamp for provenance */
|
|
94
|
+
timestamp?: string;
|
|
95
|
+
/** Additional context metadata */
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
/** Pre-generated plan ID (for deterministic parsing) */
|
|
98
|
+
planId?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Hint for path-based format detection
|
|
102
|
+
*
|
|
103
|
+
* Provides file path and sibling file information to improve
|
|
104
|
+
* detection accuracy for formats that use folder conventions.
|
|
105
|
+
*/
|
|
106
|
+
export interface PathDetectionHint {
|
|
107
|
+
/** File path being analyzed */
|
|
108
|
+
filePath: string;
|
|
109
|
+
/** Sibling file names in the same directory */
|
|
110
|
+
siblingFiles?: string[];
|
|
111
|
+
/** Parent directory names (innermost first) */
|
|
112
|
+
parentDirs?: string[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Options for adapter operations
|
|
116
|
+
*/
|
|
117
|
+
export interface AdapterOptions {
|
|
118
|
+
/** Preserve comments from source */
|
|
119
|
+
preserveComments?: boolean;
|
|
120
|
+
/** Preserve metadata from source */
|
|
121
|
+
preserveMetadata?: boolean;
|
|
122
|
+
/** Strict validation mode */
|
|
123
|
+
strict?: boolean;
|
|
124
|
+
/** Format-specific options */
|
|
125
|
+
formatOptions?: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Metadata about an adapter
|
|
129
|
+
*/
|
|
130
|
+
export interface AdapterMetadata {
|
|
131
|
+
/** Adapter name (e.g., "speckit", "bmad") */
|
|
132
|
+
name: string;
|
|
133
|
+
/** Adapter version */
|
|
134
|
+
version: string;
|
|
135
|
+
/** Human-readable display name */
|
|
136
|
+
displayName: string;
|
|
137
|
+
/** Short description of what this adapter handles */
|
|
138
|
+
description: string;
|
|
139
|
+
/** File extensions supported (e.g., [".md", ".spec.md"]) */
|
|
140
|
+
extensions: readonly string[];
|
|
141
|
+
/** Format identifiers (e.g., ["speckit", "spec"]) */
|
|
142
|
+
formats: readonly string[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Core interface for format adapters
|
|
146
|
+
*
|
|
147
|
+
* Adapters convert between external planning formats and APS.
|
|
148
|
+
* Each adapter should handle one external format (e.g., SpecKit, BMAD).
|
|
149
|
+
*/
|
|
150
|
+
export interface FormatAdapter {
|
|
151
|
+
/** Adapter metadata */
|
|
152
|
+
readonly metadata: AdapterMetadata;
|
|
153
|
+
/**
|
|
154
|
+
* Detect if this adapter can handle the given content
|
|
155
|
+
*
|
|
156
|
+
* @param content - Raw content to analyze
|
|
157
|
+
* @returns Detection result with confidence score
|
|
158
|
+
*/
|
|
159
|
+
detect(content: string): DetectionResult;
|
|
160
|
+
/**
|
|
161
|
+
* Parse external format content into APS
|
|
162
|
+
*
|
|
163
|
+
* @param content - Raw content in external format
|
|
164
|
+
* @param context - Context for provenance tracking
|
|
165
|
+
* @param options - Parsing options
|
|
166
|
+
* @returns Parse result with APS plan or errors
|
|
167
|
+
*/
|
|
168
|
+
parse(content: string, context?: ParseContext, options?: AdapterOptions): Promise<ParseResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Serialize APS plan to external format
|
|
171
|
+
*
|
|
172
|
+
* @param plan - APS plan to serialize
|
|
173
|
+
* @param options - Serialization options
|
|
174
|
+
* @returns Serialize result with content or errors
|
|
175
|
+
*/
|
|
176
|
+
serialize(plan: APSPlan, options?: AdapterOptions): Promise<SerializeResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Validate external format content
|
|
179
|
+
*
|
|
180
|
+
* Validates the content without full conversion to APS.
|
|
181
|
+
* Useful for fast validation feedback.
|
|
182
|
+
*
|
|
183
|
+
* @param content - Raw content to validate
|
|
184
|
+
* @param options - Validation options
|
|
185
|
+
* @returns Validation result
|
|
186
|
+
*/
|
|
187
|
+
validate(content: string, options?: AdapterOptions): Promise<ValidationResult>;
|
|
188
|
+
/**
|
|
189
|
+
* Detect if this adapter can handle content using file path hints
|
|
190
|
+
*
|
|
191
|
+
* Optional method that uses folder structure and sibling files
|
|
192
|
+
* to improve detection accuracy. Falls back to content-only
|
|
193
|
+
* detection if not implemented.
|
|
194
|
+
*
|
|
195
|
+
* @param content - Raw content to analyze
|
|
196
|
+
* @param hint - Path and directory information
|
|
197
|
+
* @returns Detection result with confidence score
|
|
198
|
+
*/
|
|
199
|
+
detectWithPath?(content: string, hint: PathDetectionHint): DetectionResult;
|
|
200
|
+
/**
|
|
201
|
+
* Check if this adapter can import from a given format
|
|
202
|
+
*
|
|
203
|
+
* @param format - Format identifier or file extension
|
|
204
|
+
* @returns True if adapter supports importing from this format
|
|
205
|
+
*/
|
|
206
|
+
canImport(format: string): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Check if this adapter can export to a given format
|
|
209
|
+
*
|
|
210
|
+
* @param format - Format identifier or file extension
|
|
211
|
+
* @returns True if adapter supports exporting to this format
|
|
212
|
+
*/
|
|
213
|
+
canExport(format: string): boolean;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Abstract base class for format adapters
|
|
217
|
+
*
|
|
218
|
+
* Provides common functionality and structure for concrete adapters.
|
|
219
|
+
*/
|
|
220
|
+
export declare abstract class BaseFormatAdapter implements FormatAdapter {
|
|
221
|
+
protected options: AdapterOptions;
|
|
222
|
+
abstract readonly metadata: AdapterMetadata;
|
|
223
|
+
constructor(options?: AdapterOptions);
|
|
224
|
+
abstract detect(content: string): DetectionResult;
|
|
225
|
+
abstract parse(content: string, context?: ParseContext, options?: AdapterOptions): Promise<ParseResult>;
|
|
226
|
+
abstract serialize(plan: APSPlan, options?: AdapterOptions): Promise<SerializeResult>;
|
|
227
|
+
abstract validate(content: string, options?: AdapterOptions): Promise<ValidationResult>;
|
|
228
|
+
canImport(format: string): boolean;
|
|
229
|
+
canExport(format: string): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Helper to create a successful parse result
|
|
232
|
+
*/
|
|
233
|
+
protected createParseSuccess(data: APSPlan, warnings?: AdapterWarning[]): ParseResult;
|
|
234
|
+
/**
|
|
235
|
+
* Helper to create a failed parse result
|
|
236
|
+
*/
|
|
237
|
+
protected createParseError(errors: AdapterError[], warnings?: AdapterWarning[]): ParseResult;
|
|
238
|
+
/**
|
|
239
|
+
* Helper to create a successful serialize result
|
|
240
|
+
*/
|
|
241
|
+
protected createSerializeSuccess(content: string, warnings?: AdapterWarning[], metadata?: Record<string, unknown>): SerializeResult;
|
|
242
|
+
/**
|
|
243
|
+
* Helper to create a failed serialize result
|
|
244
|
+
*/
|
|
245
|
+
protected createSerializeError(errors: AdapterError[], warnings?: AdapterWarning[]): SerializeResult;
|
|
246
|
+
/**
|
|
247
|
+
* Helper to add an error
|
|
248
|
+
*/
|
|
249
|
+
protected addError(errors: AdapterError[], code: string, message: string, path?: string, details?: unknown): void;
|
|
250
|
+
/**
|
|
251
|
+
* Helper to add a warning
|
|
252
|
+
*/
|
|
253
|
+
protected addWarning(warnings: AdapterWarning[], code: string, message: string, path?: string, details?: unknown): void;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/base/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG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}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Adapter Framework Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the core interfaces for format adapters that convert between
|
|
5
|
+
* external planning formats (SpecKit, BMAD, etc.) and APS.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for format adapters
|
|
9
|
+
*
|
|
10
|
+
* Provides common functionality and structure for concrete adapters.
|
|
11
|
+
*/
|
|
12
|
+
export class BaseFormatAdapter {
|
|
13
|
+
options;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
canImport(format) {
|
|
18
|
+
const normalized = format.toLowerCase().replace(/^\./, '');
|
|
19
|
+
return (this.metadata.formats.includes(normalized) ||
|
|
20
|
+
this.metadata.extensions.some((ext) => ext.replace(/^\./, '') === normalized));
|
|
21
|
+
}
|
|
22
|
+
canExport(format) {
|
|
23
|
+
return this.canImport(format);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Helper to create a successful parse result
|
|
27
|
+
*/
|
|
28
|
+
createParseSuccess(data, warnings) {
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
data,
|
|
32
|
+
warnings: warnings && warnings.length > 0 ? warnings : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Helper to create a failed parse result
|
|
37
|
+
*/
|
|
38
|
+
createParseError(errors, warnings) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
errors,
|
|
42
|
+
warnings: warnings && warnings.length > 0 ? warnings : undefined,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Helper to create a successful serialize result
|
|
47
|
+
*/
|
|
48
|
+
createSerializeSuccess(content, warnings, metadata) {
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
content,
|
|
52
|
+
warnings: warnings && warnings.length > 0 ? warnings : undefined,
|
|
53
|
+
metadata,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Helper to create a failed serialize result
|
|
58
|
+
*/
|
|
59
|
+
createSerializeError(errors, warnings) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
errors,
|
|
63
|
+
warnings: warnings && warnings.length > 0 ? warnings : undefined,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Helper to add an error
|
|
68
|
+
*/
|
|
69
|
+
addError(errors, code, message, path, details) {
|
|
70
|
+
errors.push({ code, message, path, details });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Helper to add a warning
|
|
74
|
+
*/
|
|
75
|
+
addWarning(warnings, code, message, path, details) {
|
|
76
|
+
warnings.push({ code, message, path, details });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { AdapterError, AdapterWarning, ParseResult, SerializeResult, DetectionResult } from './types.js';
|
|
2
|
+
export declare function generateDeterministicPlanId(content: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Create a detection result
|
|
5
|
+
*
|
|
6
|
+
* @param detected - Whether format was detected
|
|
7
|
+
* @param confidence - Confidence score (0-100)
|
|
8
|
+
* @param reason - Optional reason
|
|
9
|
+
* @returns Detection result
|
|
10
|
+
*/
|
|
11
|
+
export declare function createDetection(detected: boolean, confidence: number, reason?: string): DetectionResult;
|
|
12
|
+
/**
|
|
13
|
+
* Create an adapter error
|
|
14
|
+
*
|
|
15
|
+
* @param code - Error code
|
|
16
|
+
* @param message - Error message
|
|
17
|
+
* @param options - Additional options
|
|
18
|
+
* @returns Adapter error
|
|
19
|
+
*/
|
|
20
|
+
export declare function createError(code: string, message: string, options?: {
|
|
21
|
+
path?: string;
|
|
22
|
+
line?: number;
|
|
23
|
+
column?: number;
|
|
24
|
+
details?: unknown;
|
|
25
|
+
}): AdapterError;
|
|
26
|
+
/**
|
|
27
|
+
* Create an adapter warning
|
|
28
|
+
*
|
|
29
|
+
* @param code - Warning code
|
|
30
|
+
* @param message - Warning message
|
|
31
|
+
* @param options - Additional options
|
|
32
|
+
* @returns Adapter warning
|
|
33
|
+
*/
|
|
34
|
+
export declare function createWarning(code: string, message: string, options?: {
|
|
35
|
+
path?: string;
|
|
36
|
+
line?: number;
|
|
37
|
+
column?: number;
|
|
38
|
+
details?: unknown;
|
|
39
|
+
}): AdapterWarning;
|
|
40
|
+
/**
|
|
41
|
+
* Check if content matches a pattern
|
|
42
|
+
*
|
|
43
|
+
* Useful for format detection.
|
|
44
|
+
*
|
|
45
|
+
* @param content - Content to check
|
|
46
|
+
* @param patterns - Array of regex patterns or strings
|
|
47
|
+
* @returns Number of patterns matched (0 to patterns.length)
|
|
48
|
+
*/
|
|
49
|
+
export declare function matchesPatterns(content: string, patterns: Array<string | RegExp>): number;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate confidence score based on pattern matches
|
|
52
|
+
*
|
|
53
|
+
* @param matchCount - Number of patterns matched
|
|
54
|
+
* @param totalPatterns - Total number of patterns checked
|
|
55
|
+
* @param requiredMatches - Minimum matches for 100% confidence
|
|
56
|
+
* @returns Confidence score (0-100)
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateConfidence(matchCount: number, totalPatterns: number, requiredMatches?: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Extract file extension from filename or path
|
|
61
|
+
*
|
|
62
|
+
* @param filename - Filename or path
|
|
63
|
+
* @returns Extension (including dot) or empty string
|
|
64
|
+
*/
|
|
65
|
+
export declare function getExtension(filename: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Normalize format identifier
|
|
68
|
+
*
|
|
69
|
+
* Removes leading dot and converts to lowercase.
|
|
70
|
+
*
|
|
71
|
+
* @param format - Format identifier or extension
|
|
72
|
+
* @returns Normalized format
|
|
73
|
+
*/
|
|
74
|
+
export declare function normalizeFormat(format: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Format errors for display
|
|
77
|
+
*
|
|
78
|
+
* @param errors - Array of errors
|
|
79
|
+
* @returns Formatted error string
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatErrors(errors: AdapterError[]): string;
|
|
82
|
+
/**
|
|
83
|
+
* Format warnings for display
|
|
84
|
+
*
|
|
85
|
+
* @param warnings - Array of warnings
|
|
86
|
+
* @returns Formatted warning string
|
|
87
|
+
*/
|
|
88
|
+
export declare function formatWarnings(warnings: AdapterWarning[]): string;
|
|
89
|
+
/**
|
|
90
|
+
* Merge parse results
|
|
91
|
+
*
|
|
92
|
+
* Useful when parsing composite formats.
|
|
93
|
+
*
|
|
94
|
+
* @param results - Array of parse results
|
|
95
|
+
* @returns Merged result
|
|
96
|
+
*/
|
|
97
|
+
export declare function mergeParseResults(results: ParseResult[]): ParseResult;
|
|
98
|
+
/**
|
|
99
|
+
* Check if result has errors
|
|
100
|
+
*
|
|
101
|
+
* @param result - Parse or serialize result
|
|
102
|
+
* @returns True if result has errors
|
|
103
|
+
*/
|
|
104
|
+
export declare function hasErrors(result: ParseResult | SerializeResult): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Check if result has warnings
|
|
107
|
+
*
|
|
108
|
+
* @param result - Parse or serialize result
|
|
109
|
+
* @returns True if result has warnings
|
|
110
|
+
*/
|
|
111
|
+
export declare function hasWarnings(result: ParseResult | SerializeResult): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Extract first line from content (useful for format detection)
|
|
114
|
+
*
|
|
115
|
+
* @param content - Content string
|
|
116
|
+
* @returns First non-empty line or empty string
|
|
117
|
+
*/
|
|
118
|
+
export declare function getFirstLine(content: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Count occurrences of pattern in content
|
|
121
|
+
*
|
|
122
|
+
* @param content - Content to search
|
|
123
|
+
* @param pattern - Pattern to count
|
|
124
|
+
* @returns Number of occurrences
|
|
125
|
+
*/
|
|
126
|
+
export declare function countOccurrences(content: string, pattern: string | RegExp): number;
|
|
127
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,eAAe,CAMjB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,YAAY,CAMd;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,cAAc,CAMhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAczF;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,eAAe,GAAE,MAA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