@codeledger/engine 0.7.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/ccs/index.d.ts +11 -0
- package/dist/ccs/index.d.ts.map +1 -0
- package/dist/ccs/index.js +10 -0
- package/dist/ccs/index.js.map +1 -0
- package/dist/ccs/score.d.ts +61 -0
- package/dist/ccs/score.d.ts.map +1 -0
- package/dist/ccs/score.js +250 -0
- package/dist/ccs/score.js.map +1 -0
- package/dist/ecl/index.d.ts +9 -0
- package/dist/ecl/index.d.ts.map +1 -0
- package/dist/ecl/index.js +9 -0
- package/dist/ecl/index.js.map +1 -0
- package/dist/ecl/ledger.d.ts +84 -0
- package/dist/ecl/ledger.d.ts.map +1 -0
- package/dist/ecl/ledger.js +235 -0
- package/dist/ecl/ledger.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/iole/expansion-ladder.d.ts +51 -0
- package/dist/iole/expansion-ladder.d.ts.map +1 -0
- package/dist/iole/expansion-ladder.js +153 -0
- package/dist/iole/expansion-ladder.js.map +1 -0
- package/dist/iole/failure-vector.d.ts +21 -0
- package/dist/iole/failure-vector.d.ts.map +1 -0
- package/dist/iole/failure-vector.js +156 -0
- package/dist/iole/failure-vector.js.map +1 -0
- package/dist/iole/index.d.ts +19 -0
- package/dist/iole/index.d.ts.map +1 -0
- package/dist/iole/index.js +17 -0
- package/dist/iole/index.js.map +1 -0
- package/dist/iole/intent-decomposition.d.ts +33 -0
- package/dist/iole/intent-decomposition.d.ts.map +1 -0
- package/dist/iole/intent-decomposition.js +252 -0
- package/dist/iole/intent-decomposition.js.map +1 -0
- package/dist/iole/intent-signature.d.ts +37 -0
- package/dist/iole/intent-signature.d.ts.map +1 -0
- package/dist/iole/intent-signature.js +112 -0
- package/dist/iole/intent-signature.js.map +1 -0
- package/dist/iole/outcome-score.d.ts +25 -0
- package/dist/iole/outcome-score.d.ts.map +1 -0
- package/dist/iole/outcome-score.js +128 -0
- package/dist/iole/outcome-score.js.map +1 -0
- package/dist/isc/index.d.ts +8 -0
- package/dist/isc/index.d.ts.map +1 -0
- package/dist/isc/index.js +8 -0
- package/dist/isc/index.js.map +1 -0
- package/dist/isc/score.d.ts +27 -0
- package/dist/isc/score.d.ts.map +1 -0
- package/dist/isc/score.js +347 -0
- package/dist/isc/score.js.map +1 -0
- package/dist/license/index.d.ts +14 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/index.js +11 -0
- package/dist/license/index.js.map +1 -0
- package/dist/license/parse.d.ts +42 -0
- package/dist/license/parse.d.ts.map +1 -0
- package/dist/license/parse.js +106 -0
- package/dist/license/parse.js.map +1 -0
- package/dist/license/publicKey.d.ts +37 -0
- package/dist/license/publicKey.d.ts.map +1 -0
- package/dist/license/publicKey.js +48 -0
- package/dist/license/publicKey.js.map +1 -0
- package/dist/license/verify.d.ts +33 -0
- package/dist/license/verify.d.ts.map +1 -0
- package/dist/license/verify.js +82 -0
- package/dist/license/verify.js.map +1 -0
- package/dist/orchestrator/index.d.ts +10 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +10 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +44 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +182 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/policy-sim/index.d.ts +8 -0
- package/dist/policy-sim/index.d.ts.map +1 -0
- package/dist/policy-sim/index.js +8 -0
- package/dist/policy-sim/index.js.map +1 -0
- package/dist/policy-sim/simulate.d.ts +18 -0
- package/dist/policy-sim/simulate.d.ts.map +1 -0
- package/dist/policy-sim/simulate.js +61 -0
- package/dist/policy-sim/simulate.js.map +1 -0
- package/dist/provenance/graph.d.ts +42 -0
- package/dist/provenance/graph.d.ts.map +1 -0
- package/dist/provenance/graph.js +139 -0
- package/dist/provenance/graph.js.map +1 -0
- package/dist/provenance/index.d.ts +8 -0
- package/dist/provenance/index.d.ts.map +1 -0
- package/dist/provenance/index.js +8 -0
- package/dist/provenance/index.js.map +1 -0
- package/dist/sce/index.d.ts +15 -0
- package/dist/sce/index.d.ts.map +1 -0
- package/dist/sce/index.js +14 -0
- package/dist/sce/index.js.map +1 -0
- package/dist/sce/slice-builder.d.ts +35 -0
- package/dist/sce/slice-builder.d.ts.map +1 -0
- package/dist/sce/slice-builder.js +198 -0
- package/dist/sce/slice-builder.js.map +1 -0
- package/dist/sce/symbol-graph.d.ts +21 -0
- package/dist/sce/symbol-graph.d.ts.map +1 -0
- package/dist/sce/symbol-graph.js +187 -0
- package/dist/sce/symbol-graph.js.map +1 -0
- package/dist/team-ledger/index.d.ts +8 -0
- package/dist/team-ledger/index.d.ts.map +1 -0
- package/dist/team-ledger/index.js +8 -0
- package/dist/team-ledger/index.js.map +1 -0
- package/dist/team-ledger/ledger.d.ts +48 -0
- package/dist/team-ledger/ledger.d.ts.map +1 -0
- package/dist/team-ledger/ledger.js +208 -0
- package/dist/team-ledger/ledger.js.map +1 -0
- package/dist/team-metrics/index.d.ts +8 -0
- package/dist/team-metrics/index.d.ts.map +1 -0
- package/dist/team-metrics/index.js +8 -0
- package/dist/team-metrics/index.js.map +1 -0
- package/dist/team-metrics/metrics.d.ts +42 -0
- package/dist/team-metrics/metrics.d.ts.map +1 -0
- package/dist/team-metrics/metrics.js +156 -0
- package/dist/team-metrics/metrics.js.map +1 -0
- package/dist/team-policy/index.d.ts +8 -0
- package/dist/team-policy/index.d.ts.map +1 -0
- package/dist/team-policy/index.js +8 -0
- package/dist/team-policy/index.js.map +1 -0
- package/dist/team-policy/policy.d.ts +35 -0
- package/dist/team-policy/policy.d.ts.map +1 -0
- package/dist/team-policy/policy.js +100 -0
- package/dist/team-policy/policy.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECL-Lite — Local Context Ledger
|
|
3
|
+
*
|
|
4
|
+
* Provides persistent institutional memory for CodeLedger. Records every
|
|
5
|
+
* execution cycle to `.codeledger/ecl-lite.jsonl` (JSON Lines, append-only).
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Append execution outcomes (success/failure + context used)
|
|
9
|
+
* - Build and query success/failure indexes
|
|
10
|
+
* - Expose ledger status, inspection, and pruning
|
|
11
|
+
*
|
|
12
|
+
* Format: JSON Lines — one EclLiteEntry per line. Human-readable, no SQLite
|
|
13
|
+
* dependency. Safe for concurrent reads; single-writer append model.
|
|
14
|
+
*
|
|
15
|
+
* Deterministic: integer weights only, no floats in the index.
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs';
|
|
18
|
+
import { join, dirname } from 'path';
|
|
19
|
+
import { createHash } from 'crypto';
|
|
20
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
21
|
+
export const ECL_FILENAME = 'ecl-lite.jsonl';
|
|
22
|
+
const MAX_ENTRIES_DEFAULT = 2000;
|
|
23
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
24
|
+
/** Derive the ECL-lite path for a given repo root */
|
|
25
|
+
export function eclPath(repoRoot) {
|
|
26
|
+
return join(repoRoot, '.codeledger', ECL_FILENAME);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Append a new execution cycle entry to the ledger.
|
|
30
|
+
* Creates the file (and `.codeledger/` dir) if they don't exist.
|
|
31
|
+
*/
|
|
32
|
+
export function recordExecution(repoRoot, entry) {
|
|
33
|
+
const path = eclPath(repoRoot);
|
|
34
|
+
ensureDir(dirname(path));
|
|
35
|
+
appendFileSync(path, JSON.stringify(entry) + '\n', 'utf-8');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build an EclLiteEntry from the inputs of a completed execution cycle.
|
|
39
|
+
* Computes the contextHash deterministically from the sorted file list.
|
|
40
|
+
*/
|
|
41
|
+
export function buildEntry(intentSignature, files, symbols, expansionLevel, outcome, confidenceScore, failureVector, intentCategory) {
|
|
42
|
+
const sorted = [...files].sort();
|
|
43
|
+
const contextHash = createHash('sha256')
|
|
44
|
+
.update(sorted.join('\n'))
|
|
45
|
+
.digest('hex')
|
|
46
|
+
.slice(0, 16);
|
|
47
|
+
return {
|
|
48
|
+
intentSignature,
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
files: sorted,
|
|
51
|
+
symbols: [...new Set(symbols)].sort(),
|
|
52
|
+
expansionLevel,
|
|
53
|
+
outcome,
|
|
54
|
+
failureVector,
|
|
55
|
+
contextHash,
|
|
56
|
+
confidenceScore,
|
|
57
|
+
intentCategory,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Load all entries from the ledger.
|
|
62
|
+
* Returns empty array if ledger does not exist or is malformed.
|
|
63
|
+
*/
|
|
64
|
+
export function loadEntries(repoRoot) {
|
|
65
|
+
const path = eclPath(repoRoot);
|
|
66
|
+
if (!existsSync(path))
|
|
67
|
+
return [];
|
|
68
|
+
const lines = readFileSync(path, 'utf-8').split('\n').filter((l) => l.trim());
|
|
69
|
+
const entries = [];
|
|
70
|
+
for (const line of lines) {
|
|
71
|
+
try {
|
|
72
|
+
entries.push(JSON.parse(line));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Skip malformed lines — ledger is append-only; partial writes can corrupt a line
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build the success/failure weight index from ledger entries.
|
|
82
|
+
*
|
|
83
|
+
* Uses integer arithmetic only — deterministic, no floats.
|
|
84
|
+
* successWeight++ on each success, failureWeight++ on each failure.
|
|
85
|
+
*/
|
|
86
|
+
export function buildWeightIndex(entries) {
|
|
87
|
+
const index = new Map();
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
const existing = index.get(entry.intentSignature) ?? {
|
|
90
|
+
intentSignature: entry.intentSignature,
|
|
91
|
+
successWeight: 0,
|
|
92
|
+
failureWeight: 0,
|
|
93
|
+
lastUpdated: 0,
|
|
94
|
+
};
|
|
95
|
+
if (entry.outcome === 'success') {
|
|
96
|
+
existing.successWeight++;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
existing.failureWeight++;
|
|
100
|
+
}
|
|
101
|
+
existing.lastUpdated = Math.max(existing.lastUpdated, entry.timestamp);
|
|
102
|
+
index.set(entry.intentSignature, existing);
|
|
103
|
+
}
|
|
104
|
+
return index;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Compute the historical success rate for an intent signature.
|
|
108
|
+
* Returns 0.5 (neutral) if no history exists.
|
|
109
|
+
*/
|
|
110
|
+
export function historicalSuccessRate(entries, intentSignature) {
|
|
111
|
+
return historicalSuccessContext(entries, intentSignature).rate;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns both the historical success rate AND the sample size used.
|
|
115
|
+
*
|
|
116
|
+
* Falls back to category-level aggregation when the specific intent signature
|
|
117
|
+
* has < 5 entries — avoids early-data noise from single-entry signatures.
|
|
118
|
+
*
|
|
119
|
+
* Priority:
|
|
120
|
+
* 1. Exact intentSignature match (>= 5 entries) → specific rate
|
|
121
|
+
* 2. intentCategory match (< 5 exact OR no exact) → category rate
|
|
122
|
+
* 3. No data → 0.5 neutral prior
|
|
123
|
+
*/
|
|
124
|
+
export function historicalSuccessContext(entries, intentSignature, intentCategory) {
|
|
125
|
+
const exact = entries.filter((e) => e.intentSignature === intentSignature);
|
|
126
|
+
if (exact.length >= 5) {
|
|
127
|
+
const successes = exact.filter((e) => e.outcome === 'success').length;
|
|
128
|
+
return { rate: successes / exact.length, sampleSize: exact.length };
|
|
129
|
+
}
|
|
130
|
+
// Fall back to category if available
|
|
131
|
+
if (intentCategory && intentCategory !== 'general_task') {
|
|
132
|
+
const byCategory = entries.filter((e) => e.intentCategory === intentCategory);
|
|
133
|
+
if (byCategory.length > 0) {
|
|
134
|
+
const successes = byCategory.filter((e) => e.outcome === 'success').length;
|
|
135
|
+
return { rate: successes / byCategory.length, sampleSize: byCategory.length };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Exact match exists but < 5 — still use it (better than nothing), report small size
|
|
139
|
+
if (exact.length > 0) {
|
|
140
|
+
const successes = exact.filter((e) => e.outcome === 'success').length;
|
|
141
|
+
return { rate: successes / exact.length, sampleSize: exact.length };
|
|
142
|
+
}
|
|
143
|
+
return { rate: 0.5, sampleSize: 0 }; // neutral prior
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Build the failure hotspot index — files frequently implicated in failures.
|
|
147
|
+
* Returns hotspots sorted by implicationRate descending.
|
|
148
|
+
*
|
|
149
|
+
* v2.1.1: tracks lastFailureTimestamp per file for recency decay in slice-builder.
|
|
150
|
+
*/
|
|
151
|
+
export function buildFailureHotspots(entries) {
|
|
152
|
+
const failCounts = new Map();
|
|
153
|
+
const successCounts = new Map();
|
|
154
|
+
const lastFailTs = new Map();
|
|
155
|
+
for (const entry of entries) {
|
|
156
|
+
const implicated = entry.failureVector?.implicated_files ?? [];
|
|
157
|
+
if (entry.outcome === 'failure') {
|
|
158
|
+
for (const f of implicated) {
|
|
159
|
+
failCounts.set(f, (failCounts.get(f) ?? 0) + 1);
|
|
160
|
+
// Track the most recent failure timestamp for recency decay
|
|
161
|
+
const prev = lastFailTs.get(f) ?? 0;
|
|
162
|
+
if (entry.timestamp > prev)
|
|
163
|
+
lastFailTs.set(f, entry.timestamp);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Files in successful bundles count as "success context"
|
|
168
|
+
for (const f of entry.files) {
|
|
169
|
+
successCounts.set(f, (successCounts.get(f) ?? 0) + 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const hotspots = [];
|
|
174
|
+
for (const [file, failureCount] of failCounts) {
|
|
175
|
+
const successCount = successCounts.get(file) ?? 0;
|
|
176
|
+
const total = failureCount + successCount;
|
|
177
|
+
hotspots.push({
|
|
178
|
+
file,
|
|
179
|
+
failureCount,
|
|
180
|
+
successCount,
|
|
181
|
+
implicationRate: total > 0 ? failureCount / total : 0,
|
|
182
|
+
lastFailureTimestamp: lastFailTs.get(file) ?? 0,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return hotspots.sort((a, b) => b.implicationRate - a.implicationRate);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Compute overall ledger status summary.
|
|
189
|
+
*/
|
|
190
|
+
export function ledgerStatus(repoRoot) {
|
|
191
|
+
const path = eclPath(repoRoot);
|
|
192
|
+
const entries = loadEntries(repoRoot);
|
|
193
|
+
const successes = entries.filter((e) => e.outcome === 'success').length;
|
|
194
|
+
const failures = entries.filter((e) => e.outcome === 'failure').length;
|
|
195
|
+
const total = entries.length;
|
|
196
|
+
const uniqueSigs = new Set(entries.map((e) => e.intentSignature)).size;
|
|
197
|
+
const lastEntry = entries[entries.length - 1];
|
|
198
|
+
return {
|
|
199
|
+
entry_count: total,
|
|
200
|
+
success_count: successes,
|
|
201
|
+
failure_count: failures,
|
|
202
|
+
overall_success_rate: total > 0 ? successes / total : 0,
|
|
203
|
+
top_failure_hotspots: buildFailureHotspots(entries).slice(0, 10),
|
|
204
|
+
unique_intent_signatures: uniqueSigs,
|
|
205
|
+
ledger_path: path,
|
|
206
|
+
last_entry_at: lastEntry
|
|
207
|
+
? new Date(lastEntry.timestamp).toISOString()
|
|
208
|
+
: null,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Prune old entries to keep the ledger bounded.
|
|
213
|
+
* Keeps the most recent `maxEntries` entries (default 2000).
|
|
214
|
+
* Rewrites the entire file atomically (temp-write then rename not available
|
|
215
|
+
* in pure Node fs sync, so writes to path directly).
|
|
216
|
+
*/
|
|
217
|
+
export function pruneLedger(repoRoot, maxEntries = MAX_ENTRIES_DEFAULT) {
|
|
218
|
+
const path = eclPath(repoRoot);
|
|
219
|
+
if (!existsSync(path))
|
|
220
|
+
return 0;
|
|
221
|
+
const entries = loadEntries(repoRoot);
|
|
222
|
+
if (entries.length <= maxEntries)
|
|
223
|
+
return 0;
|
|
224
|
+
const pruned = entries.length - maxEntries;
|
|
225
|
+
const kept = entries.slice(-maxEntries);
|
|
226
|
+
writeFileSync(path, kept.map((e) => JSON.stringify(e)).join('\n') + '\n', 'utf-8');
|
|
227
|
+
return pruned;
|
|
228
|
+
}
|
|
229
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
230
|
+
function ensureDir(dir) {
|
|
231
|
+
if (!existsSync(dir)) {
|
|
232
|
+
mkdirSync(dir, { recursive: true });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/ecl/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AASpC,iFAAiF;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAC7C,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,iFAAiF;AAEjF,qDAAqD;AACrD,MAAM,UAAU,OAAO,CAAC,QAAgB;IACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,KAAmB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AM,CAAC;AAChB,CAAC;AAED,iFAAiF;AAEjF,SAAS,SAAS,CAAC,GAAW;IAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codeledger/engine — Deterministic Context Orchestration Layer (DCOL)
|
|
3
|
+
*
|
|
4
|
+
* v2 subsystems:
|
|
5
|
+
*
|
|
6
|
+
* SCE (Structural Context Engine)
|
|
7
|
+
* Symbol-level code analysis: build a symbol graph, then extract the
|
|
8
|
+
* Minimal Sufficient Code Slice (MSCS) for a task. Reduces token usage
|
|
9
|
+
* by including only symbols required for the task + their dependency chain.
|
|
10
|
+
* Execution path signals: failure hotspots from ECL-Lite boost symbol ranking.
|
|
11
|
+
*
|
|
12
|
+
* IOLE (Intent & Outcome Loop Engine)
|
|
13
|
+
* Eliminates agent drift: derive a stable intent signature, parse failure
|
|
14
|
+
* vectors from test/build output, escalate context via the 4-level expansion
|
|
15
|
+
* ladder, track outcome scores across iterations, and decompose intents into
|
|
16
|
+
* structured IntentObjects for exemplar matching and cross-session comparison.
|
|
17
|
+
*
|
|
18
|
+
* ECL-Lite (Local Context Ledger)
|
|
19
|
+
* Persistent institutional memory: records execution outcomes to
|
|
20
|
+
* `.codeledger/ecl-lite.jsonl`, builds success/failure weight indexes, and
|
|
21
|
+
* surfaces failure hotspots that feed back into SCE + IOLE.
|
|
22
|
+
*
|
|
23
|
+
* CCS (Context Confidence Score)
|
|
24
|
+
* Pre-execution certification: deterministic [0,1] score from 5 factors
|
|
25
|
+
* (dependency coverage, test coverage, historical success, symbol completeness,
|
|
26
|
+
* expansion efficiency). Recommends proceed / expand / block before execution.
|
|
27
|
+
*
|
|
28
|
+
* ISC (Intent Sufficiency Check)
|
|
29
|
+
* PRE-CONTEXT certification layer (v2.2). Evaluates task prompt quality
|
|
30
|
+
* before context construction begins. Five-factor scoring (token signal,
|
|
31
|
+
* operation clarity, domain clarity, target specificity, constraint presence)
|
|
32
|
+
* gates the pipeline: SUFFICIENT / WEAK / INSUFFICIENT. Deterministic,
|
|
33
|
+
* local-only, zero ML.
|
|
34
|
+
*
|
|
35
|
+
* Design principles (non-negotiable):
|
|
36
|
+
* - Deterministic > probabilistic
|
|
37
|
+
* - Minimal Sufficient Context (not maximum context)
|
|
38
|
+
* - Local-first, no external APIs
|
|
39
|
+
* - Bounded execution and termination guarantees
|
|
40
|
+
* - Outcome-aware: every execution cycle feeds back into future context selection
|
|
41
|
+
*/
|
|
42
|
+
export * from './sce/index.js';
|
|
43
|
+
export * from './iole/index.js';
|
|
44
|
+
export * from './ecl/index.js';
|
|
45
|
+
export * from './ccs/index.js';
|
|
46
|
+
export * from './isc/index.js';
|
|
47
|
+
export * from './license/index.js';
|
|
48
|
+
export * from './team-ledger/index.js';
|
|
49
|
+
export * from './team-policy/index.js';
|
|
50
|
+
export * from './team-metrics/index.js';
|
|
51
|
+
export * from './provenance/index.js';
|
|
52
|
+
export * from './policy-sim/index.js';
|
|
53
|
+
export * from './orchestrator/index.js';
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codeledger/engine — Deterministic Context Orchestration Layer (DCOL)
|
|
3
|
+
*
|
|
4
|
+
* v2 subsystems:
|
|
5
|
+
*
|
|
6
|
+
* SCE (Structural Context Engine)
|
|
7
|
+
* Symbol-level code analysis: build a symbol graph, then extract the
|
|
8
|
+
* Minimal Sufficient Code Slice (MSCS) for a task. Reduces token usage
|
|
9
|
+
* by including only symbols required for the task + their dependency chain.
|
|
10
|
+
* Execution path signals: failure hotspots from ECL-Lite boost symbol ranking.
|
|
11
|
+
*
|
|
12
|
+
* IOLE (Intent & Outcome Loop Engine)
|
|
13
|
+
* Eliminates agent drift: derive a stable intent signature, parse failure
|
|
14
|
+
* vectors from test/build output, escalate context via the 4-level expansion
|
|
15
|
+
* ladder, track outcome scores across iterations, and decompose intents into
|
|
16
|
+
* structured IntentObjects for exemplar matching and cross-session comparison.
|
|
17
|
+
*
|
|
18
|
+
* ECL-Lite (Local Context Ledger)
|
|
19
|
+
* Persistent institutional memory: records execution outcomes to
|
|
20
|
+
* `.codeledger/ecl-lite.jsonl`, builds success/failure weight indexes, and
|
|
21
|
+
* surfaces failure hotspots that feed back into SCE + IOLE.
|
|
22
|
+
*
|
|
23
|
+
* CCS (Context Confidence Score)
|
|
24
|
+
* Pre-execution certification: deterministic [0,1] score from 5 factors
|
|
25
|
+
* (dependency coverage, test coverage, historical success, symbol completeness,
|
|
26
|
+
* expansion efficiency). Recommends proceed / expand / block before execution.
|
|
27
|
+
*
|
|
28
|
+
* ISC (Intent Sufficiency Check)
|
|
29
|
+
* PRE-CONTEXT certification layer (v2.2). Evaluates task prompt quality
|
|
30
|
+
* before context construction begins. Five-factor scoring (token signal,
|
|
31
|
+
* operation clarity, domain clarity, target specificity, constraint presence)
|
|
32
|
+
* gates the pipeline: SUFFICIENT / WEAK / INSUFFICIENT. Deterministic,
|
|
33
|
+
* local-only, zero ML.
|
|
34
|
+
*
|
|
35
|
+
* Design principles (non-negotiable):
|
|
36
|
+
* - Deterministic > probabilistic
|
|
37
|
+
* - Minimal Sufficient Context (not maximum context)
|
|
38
|
+
* - Local-first, no external APIs
|
|
39
|
+
* - Bounded execution and termination guarantees
|
|
40
|
+
* - Outcome-aware: every execution cycle feeds back into future context selection
|
|
41
|
+
*/
|
|
42
|
+
export * from './sce/index.js';
|
|
43
|
+
export * from './iole/index.js';
|
|
44
|
+
export * from './ecl/index.js';
|
|
45
|
+
export * from './ccs/index.js';
|
|
46
|
+
export * from './isc/index.js';
|
|
47
|
+
// v2.4 — License verification (Ed25519 signed licenses)
|
|
48
|
+
export * from './license/index.js';
|
|
49
|
+
// v2.3 — Team + Enterprise Control Plane
|
|
50
|
+
export * from './team-ledger/index.js';
|
|
51
|
+
export * from './team-policy/index.js';
|
|
52
|
+
export * from './team-metrics/index.js';
|
|
53
|
+
export * from './provenance/index.js';
|
|
54
|
+
export * from './policy-sim/index.js';
|
|
55
|
+
export * from './orchestrator/index.js';
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,wDAAwD;AACxD,cAAc,oBAAoB,CAAC;AAEnC,yCAAyC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Context Expansion Ladder
|
|
3
|
+
*
|
|
4
|
+
* Implements deterministic context escalation when an agent is stuck.
|
|
5
|
+
* The ladder has 4 levels — each expands the context in a principled,
|
|
6
|
+
* bounded way. Escalation happens ONLY on confirmed failure; never randomly.
|
|
7
|
+
*
|
|
8
|
+
* Level 1: Minimal slice (seeds + immediate deps)
|
|
9
|
+
* Level 2: Add validation helpers + error infrastructure
|
|
10
|
+
* Level 3: Add upstream dependency chain (transitive)
|
|
11
|
+
* Level 4: Add architectural context (full module + tests)
|
|
12
|
+
*
|
|
13
|
+
* Deterministic: escalation triggered by failure count, not guesses.
|
|
14
|
+
*/
|
|
15
|
+
import type { ExpansionLevel, ExpansionLadderState, FailureVector } from '@codeledger/types';
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the expansion ladder for a new task.
|
|
18
|
+
*/
|
|
19
|
+
export declare function initExpansionLadder(task: string, intentHash: string): ExpansionLadderState;
|
|
20
|
+
/**
|
|
21
|
+
* Record a completed iteration (pass or fail) and compute the next state.
|
|
22
|
+
*
|
|
23
|
+
* - On pass: mark resolved, stay at current level
|
|
24
|
+
* - On fail: increment failure counter; if threshold reached, escalate
|
|
25
|
+
*/
|
|
26
|
+
export declare function recordOutcome(state: ExpansionLadderState, passed: boolean, failureVector?: FailureVector): ExpansionLadderState;
|
|
27
|
+
/**
|
|
28
|
+
* Get the expansion parameters for the current ladder level.
|
|
29
|
+
*
|
|
30
|
+
* These parameters are passed to the selector to widen context.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getLevelParams(level: ExpansionLevel): LevelParams;
|
|
33
|
+
/**
|
|
34
|
+
* Detect if the agent is stuck in a loop (no improvement across levels).
|
|
35
|
+
*
|
|
36
|
+
* Returns true if:
|
|
37
|
+
* - At max level AND still failing
|
|
38
|
+
* - OR the same failure hash has appeared 3+ times
|
|
39
|
+
*/
|
|
40
|
+
export declare function isStuck(state: ExpansionLadderState, failureHashes: string[]): boolean;
|
|
41
|
+
export interface LevelParams {
|
|
42
|
+
description: string;
|
|
43
|
+
dependency_depth: number;
|
|
44
|
+
include_tests: boolean;
|
|
45
|
+
include_validation: boolean;
|
|
46
|
+
include_error_infra: boolean;
|
|
47
|
+
/** Multiplier applied to selector's default max_files */
|
|
48
|
+
max_files_multiplier: number;
|
|
49
|
+
scope: 'seeds_only' | 'seeds_plus_helpers' | 'full_dependency_chain' | 'full_module';
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=expansion-ladder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expansion-ladder.d.ts","sourceRoot":"","sources":["../../src/iole/expansion-ladder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,EACd,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,oBAAoB,CAWtB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,oBAAoB,EAC3B,MAAM,EAAE,OAAO,EACf,aAAa,CAAC,EAAE,aAAa,GAC5B,oBAAoB,CAkCtB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,WAAW,CA6CjE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAerF;AAoBD,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,yDAAyD;IACzD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,YAAY,GAAG,oBAAoB,GAAG,uBAAuB,GAAG,aAAa,CAAC;CACtF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Context Expansion Ladder
|
|
3
|
+
*
|
|
4
|
+
* Implements deterministic context escalation when an agent is stuck.
|
|
5
|
+
* The ladder has 4 levels — each expands the context in a principled,
|
|
6
|
+
* bounded way. Escalation happens ONLY on confirmed failure; never randomly.
|
|
7
|
+
*
|
|
8
|
+
* Level 1: Minimal slice (seeds + immediate deps)
|
|
9
|
+
* Level 2: Add validation helpers + error infrastructure
|
|
10
|
+
* Level 3: Add upstream dependency chain (transitive)
|
|
11
|
+
* Level 4: Add architectural context (full module + tests)
|
|
12
|
+
*
|
|
13
|
+
* Deterministic: escalation triggered by failure count, not guesses.
|
|
14
|
+
*/
|
|
15
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the expansion ladder for a new task.
|
|
18
|
+
*/
|
|
19
|
+
export function initExpansionLadder(task, intentHash) {
|
|
20
|
+
return {
|
|
21
|
+
intent_hash: intentHash,
|
|
22
|
+
task,
|
|
23
|
+
current_level: 1,
|
|
24
|
+
max_level: 4,
|
|
25
|
+
iteration_count: 0,
|
|
26
|
+
failure_count: 0,
|
|
27
|
+
escalation_log: [],
|
|
28
|
+
resolved: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Record a completed iteration (pass or fail) and compute the next state.
|
|
33
|
+
*
|
|
34
|
+
* - On pass: mark resolved, stay at current level
|
|
35
|
+
* - On fail: increment failure counter; if threshold reached, escalate
|
|
36
|
+
*/
|
|
37
|
+
export function recordOutcome(state, passed, failureVector) {
|
|
38
|
+
const next = {
|
|
39
|
+
...state,
|
|
40
|
+
iteration_count: state.iteration_count + 1,
|
|
41
|
+
escalation_log: [...state.escalation_log],
|
|
42
|
+
};
|
|
43
|
+
if (passed) {
|
|
44
|
+
next.resolved = true;
|
|
45
|
+
return next;
|
|
46
|
+
}
|
|
47
|
+
next.failure_count = state.failure_count + 1;
|
|
48
|
+
// Escalate if: failure threshold reached and not yet at max level
|
|
49
|
+
const threshold = escalationThreshold(state.current_level);
|
|
50
|
+
if (next.failure_count >= threshold && state.current_level < state.max_level) {
|
|
51
|
+
const reason = failureVector
|
|
52
|
+
? `${failureVector.kind} after ${next.failure_count} failures`
|
|
53
|
+
: `${next.failure_count} consecutive failures`;
|
|
54
|
+
next.escalation_log.push({
|
|
55
|
+
from_level: state.current_level,
|
|
56
|
+
to_level: (state.current_level + 1),
|
|
57
|
+
at_iteration: next.iteration_count,
|
|
58
|
+
reason,
|
|
59
|
+
implicated_files: failureVector?.implicated_files ?? [],
|
|
60
|
+
});
|
|
61
|
+
next.current_level = (state.current_level + 1);
|
|
62
|
+
next.failure_count = 0; // reset per level
|
|
63
|
+
}
|
|
64
|
+
return next;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the expansion parameters for the current ladder level.
|
|
68
|
+
*
|
|
69
|
+
* These parameters are passed to the selector to widen context.
|
|
70
|
+
*/
|
|
71
|
+
export function getLevelParams(level) {
|
|
72
|
+
switch (level) {
|
|
73
|
+
case 1:
|
|
74
|
+
return {
|
|
75
|
+
description: 'Minimal slice — seeds + immediate dependencies',
|
|
76
|
+
dependency_depth: 1,
|
|
77
|
+
include_tests: false,
|
|
78
|
+
include_validation: false,
|
|
79
|
+
include_error_infra: false,
|
|
80
|
+
max_files_multiplier: 1.0,
|
|
81
|
+
scope: 'seeds_only',
|
|
82
|
+
};
|
|
83
|
+
case 2:
|
|
84
|
+
return {
|
|
85
|
+
description: 'Add validation helpers + error infrastructure',
|
|
86
|
+
dependency_depth: 2,
|
|
87
|
+
include_tests: false,
|
|
88
|
+
include_validation: true,
|
|
89
|
+
include_error_infra: true,
|
|
90
|
+
max_files_multiplier: 1.5,
|
|
91
|
+
scope: 'seeds_plus_helpers',
|
|
92
|
+
};
|
|
93
|
+
case 3:
|
|
94
|
+
return {
|
|
95
|
+
description: 'Add upstream dependency chain (transitive)',
|
|
96
|
+
dependency_depth: 4,
|
|
97
|
+
include_tests: true,
|
|
98
|
+
include_validation: true,
|
|
99
|
+
include_error_infra: true,
|
|
100
|
+
max_files_multiplier: 2.0,
|
|
101
|
+
scope: 'full_dependency_chain',
|
|
102
|
+
};
|
|
103
|
+
case 4:
|
|
104
|
+
return {
|
|
105
|
+
description: 'Full architectural context — complete module + tests',
|
|
106
|
+
dependency_depth: 8,
|
|
107
|
+
include_tests: true,
|
|
108
|
+
include_validation: true,
|
|
109
|
+
include_error_infra: true,
|
|
110
|
+
max_files_multiplier: 3.0,
|
|
111
|
+
scope: 'full_module',
|
|
112
|
+
};
|
|
113
|
+
default:
|
|
114
|
+
return getLevelParams(4);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Detect if the agent is stuck in a loop (no improvement across levels).
|
|
119
|
+
*
|
|
120
|
+
* Returns true if:
|
|
121
|
+
* - At max level AND still failing
|
|
122
|
+
* - OR the same failure hash has appeared 3+ times
|
|
123
|
+
*/
|
|
124
|
+
export function isStuck(state, failureHashes) {
|
|
125
|
+
if (state.current_level >= state.max_level && state.failure_count >= 2) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
// Detect repeated identical failures
|
|
129
|
+
const counts = new Map();
|
|
130
|
+
for (const h of failureHashes) {
|
|
131
|
+
counts.set(h, (counts.get(h) ?? 0) + 1);
|
|
132
|
+
}
|
|
133
|
+
for (const count of counts.values()) {
|
|
134
|
+
if (count >= 3)
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
140
|
+
/**
|
|
141
|
+
* How many failures at a given level before escalating.
|
|
142
|
+
* Lower levels escalate faster; level 3+ is patient.
|
|
143
|
+
*/
|
|
144
|
+
function escalationThreshold(level) {
|
|
145
|
+
switch (level) {
|
|
146
|
+
case 1: return 2; // escalate after 2 failures at level 1
|
|
147
|
+
case 2: return 3; // escalate after 3 failures at level 2
|
|
148
|
+
case 3: return 4; // escalate after 4 failures at level 3
|
|
149
|
+
case 4: return Infinity; // no further escalation — this is the ceiling
|
|
150
|
+
default: return 2;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=expansion-ladder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expansion-ladder.js","sourceRoot":"","sources":["../../src/iole/expansion-ladder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,iFAAiF;AAEjF;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,UAAkB;IAElB,OAAO;QACL,WAAW,EAAE,UAAU;QACvB,IAAI;QACJ,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,CAAC;QACZ,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,CAAC;QAChB,cAAc,EAAE,EAAE;QAClB,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,KAA2B,EAC3B,MAAe,EACf,aAA6B;IAE7B,MAAM,IAAI,GAAyB;QACjC,GAAG,KAAK;QACR,eAAe,EAAE,KAAK,CAAC,eAAe,GAAG,CAAC;QAC1C,cAAc,EAAE,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC;KAC1C,CAAC;IAEF,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC;IAE7C,kEAAkE;IAClE,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC3D,IAA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IAChD,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uCAAuC;QACzD,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uCAAuC;QACzD,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uCAAuC;QACzD,KAAK,CAAC,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,8CAA8C;QACvE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Failure Vector
|
|
3
|
+
*
|
|
4
|
+
* Parses agent execution failures (test output, stack traces, rejected diffs)
|
|
5
|
+
* into a structured FailureVector that the expansion ladder uses to determine
|
|
6
|
+
* which files to add in the next context iteration.
|
|
7
|
+
*
|
|
8
|
+
* Deterministic: parses raw strings, no ML, no embeddings.
|
|
9
|
+
*/
|
|
10
|
+
import type { FailureVector } from '@codeledger/types';
|
|
11
|
+
/**
|
|
12
|
+
* Parse raw output strings into a structured FailureVector.
|
|
13
|
+
*
|
|
14
|
+
* Handles:
|
|
15
|
+
* - Test runner output (vitest, jest, mocha patterns)
|
|
16
|
+
* - Node.js/TypeScript stack traces
|
|
17
|
+
* - Build errors (tsc, esbuild)
|
|
18
|
+
* - Rejected diffs (conflict markers)
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseFailureVector(outputs: string[]): FailureVector;
|
|
21
|
+
//# sourceMappingURL=failure-vector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-vector.d.ts","sourceRoot":"","sources":["../../src/iole/failure-vector.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAC;AAIpE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa,CAsCnE"}
|