@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,156 @@
|
|
|
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
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
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 function parseFailureVector(outputs) {
|
|
21
|
+
const combined = outputs.join('\n');
|
|
22
|
+
const failures = [];
|
|
23
|
+
const implicated_files = new Set();
|
|
24
|
+
const implicated_symbols = new Set();
|
|
25
|
+
// 1. Extract failing test names
|
|
26
|
+
const testFailures = extractTestFailures(combined);
|
|
27
|
+
for (const f of testFailures) {
|
|
28
|
+
failures.push(f);
|
|
29
|
+
if (f.file)
|
|
30
|
+
implicated_files.add(f.file);
|
|
31
|
+
if (f.symbol)
|
|
32
|
+
implicated_symbols.add(f.symbol);
|
|
33
|
+
}
|
|
34
|
+
// 2. Extract stack trace frames
|
|
35
|
+
const stackFrames = extractStackTraceFiles(combined);
|
|
36
|
+
for (const f of stackFrames) {
|
|
37
|
+
implicated_files.add(f);
|
|
38
|
+
}
|
|
39
|
+
// 3. Extract build errors
|
|
40
|
+
const buildErrors = extractBuildErrors(combined);
|
|
41
|
+
for (const f of buildErrors) {
|
|
42
|
+
failures.push(f);
|
|
43
|
+
if (f.file)
|
|
44
|
+
implicated_files.add(f.file);
|
|
45
|
+
}
|
|
46
|
+
// 4. Detect kind summary
|
|
47
|
+
const kind = summarizeKind(failures);
|
|
48
|
+
return {
|
|
49
|
+
kind,
|
|
50
|
+
failures,
|
|
51
|
+
implicated_files: [...implicated_files],
|
|
52
|
+
implicated_symbols: [...implicated_symbols],
|
|
53
|
+
raw_output_hash: hashOutputs(combined),
|
|
54
|
+
parsed_at: new Date().toISOString(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function extractTestFailures(output) {
|
|
58
|
+
const failures = [];
|
|
59
|
+
// Vitest/Jest: "✕ test name" or "× test name" or "FAIL src/foo.test.ts"
|
|
60
|
+
const vitestFailRe = /[✕×✗●]\s+(.+)/g;
|
|
61
|
+
let m;
|
|
62
|
+
while ((m = vitestFailRe.exec(output)) !== null) {
|
|
63
|
+
failures.push({
|
|
64
|
+
kind: 'test_failure',
|
|
65
|
+
message: m[1]?.trim() ?? '',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Jest: "● describe > test name"
|
|
69
|
+
const jestRe = /●\s+(.+)/g;
|
|
70
|
+
while ((m = jestRe.exec(output)) !== null) {
|
|
71
|
+
const msg = m[1]?.trim() ?? '';
|
|
72
|
+
if (!failures.some((f) => f.message === msg)) {
|
|
73
|
+
failures.push({ kind: 'test_failure', message: msg });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// File-level failures: "FAIL src/foo.test.ts"
|
|
77
|
+
const fileFailRe = /(?:FAIL|FAILED)\s+([\w./\-@]+\.test\.[tj]sx?)/g;
|
|
78
|
+
while ((m = fileFailRe.exec(output)) !== null) {
|
|
79
|
+
failures.push({
|
|
80
|
+
kind: 'test_failure',
|
|
81
|
+
message: `Test file failed: ${m[1]}`,
|
|
82
|
+
file: m[1],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return failures;
|
|
86
|
+
}
|
|
87
|
+
function extractStackTraceFiles(output) {
|
|
88
|
+
const files = [];
|
|
89
|
+
// Node stack trace: " at Object.<anonymous> (src/foo.ts:42:10)"
|
|
90
|
+
const stackRe = /at\s+[\w.<>[\]]+\s+\(([^)]+\.(?:ts|tsx|js|jsx)):(\d+):\d+\)/g;
|
|
91
|
+
let m;
|
|
92
|
+
while ((m = stackRe.exec(output)) !== null) {
|
|
93
|
+
if (m[1] && !m[1].includes('node_modules')) {
|
|
94
|
+
files.push(m[1]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Simple "at src/foo.ts:42" pattern
|
|
98
|
+
const simpleRe = /at\s+([\w./\-@]+\.(?:ts|tsx|js|jsx)):(\d+)/g;
|
|
99
|
+
while ((m = simpleRe.exec(output)) !== null) {
|
|
100
|
+
if (m[1] && !m[1].includes('node_modules')) {
|
|
101
|
+
files.push(m[1]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return [...new Set(files)];
|
|
105
|
+
}
|
|
106
|
+
function extractBuildErrors(output) {
|
|
107
|
+
const failures = [];
|
|
108
|
+
// TypeScript errors: "src/foo.ts(42,10): error TS2304: Cannot find name 'bar'."
|
|
109
|
+
const tscRe = /([\w./\-@]+\.tsx?)\((\d+),\d+\):\s+error\s+(TS\d+):\s+(.+)/g;
|
|
110
|
+
let m;
|
|
111
|
+
while ((m = tscRe.exec(output)) !== null) {
|
|
112
|
+
failures.push({
|
|
113
|
+
kind: 'build_error',
|
|
114
|
+
message: `${m[3]}: ${m[4]?.trim()}`,
|
|
115
|
+
file: m[1],
|
|
116
|
+
line: parseInt(m[2] ?? '0', 10),
|
|
117
|
+
symbol: extractSymbolFromTscError(m[4] ?? ''),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// ESBuild errors: "src/foo.ts:42:10: error: ..."
|
|
121
|
+
const esbuildRe = /([\w./\-@]+\.tsx?):\d+:\d+:\s+error:\s+(.+)/g;
|
|
122
|
+
while ((m = esbuildRe.exec(output)) !== null) {
|
|
123
|
+
failures.push({
|
|
124
|
+
kind: 'build_error',
|
|
125
|
+
message: m[2]?.trim() ?? '',
|
|
126
|
+
file: m[1],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return failures;
|
|
130
|
+
}
|
|
131
|
+
function extractSymbolFromTscError(msg) {
|
|
132
|
+
// "Cannot find name 'foo'" → "foo"
|
|
133
|
+
const nameRe = /'(\w+)'/;
|
|
134
|
+
const m = nameRe.exec(msg);
|
|
135
|
+
return m?.[1];
|
|
136
|
+
}
|
|
137
|
+
function summarizeKind(failures) {
|
|
138
|
+
const kinds = new Set(failures.map((f) => f.kind));
|
|
139
|
+
if (kinds.has('build_error'))
|
|
140
|
+
return 'build_error';
|
|
141
|
+
if (kinds.has('test_failure'))
|
|
142
|
+
return 'test_failure';
|
|
143
|
+
if (kinds.size > 0)
|
|
144
|
+
return [...kinds][0];
|
|
145
|
+
return 'unknown';
|
|
146
|
+
}
|
|
147
|
+
function hashOutputs(combined) {
|
|
148
|
+
// Simple non-crypto hash for deduplication (FNV-1a)
|
|
149
|
+
let h = 2166136261;
|
|
150
|
+
for (let i = 0; i < combined.length; i++) {
|
|
151
|
+
h ^= combined.charCodeAt(i);
|
|
152
|
+
h = (h * 16777619) >>> 0;
|
|
153
|
+
}
|
|
154
|
+
return h.toString(16).padStart(8, '0');
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=failure-vector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-vector.js","sourceRoot":"","sources":["../../src/iole/failure-vector.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,iFAAiF;AAEjF;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAiB;IAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAC/C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3C,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C,gCAAgC;IAChC,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;I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ACnC,oDAAoD;IACpD,IAAI,CAAC,GAAG,UAAU,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Intent & Outcome Loop Engine
|
|
3
|
+
*
|
|
4
|
+
* Eliminates agent drift and stuck loops via deterministic feedback loops.
|
|
5
|
+
*
|
|
6
|
+
* Subsystems:
|
|
7
|
+
* - intent-signature: Derive stable hash from task prompt; detect drift
|
|
8
|
+
* - failure-vector: Parse test/build/trace failures into structured form
|
|
9
|
+
* - expansion-ladder: 4-level context escalation triggered by failures
|
|
10
|
+
* - outcome-score: Track pass rates, stability, improvement trends
|
|
11
|
+
*/
|
|
12
|
+
export { deriveIntentSignature, compareIntentSignatures, } from './intent-signature.js';
|
|
13
|
+
export type { IntentDriftLevel, IntentDriftResult } from './intent-signature.js';
|
|
14
|
+
export { parseFailureVector } from './failure-vector.js';
|
|
15
|
+
export { initExpansionLadder, recordOutcome, getLevelParams, isStuck, } from './expansion-ladder.js';
|
|
16
|
+
export type { LevelParams } from './expansion-ladder.js';
|
|
17
|
+
export { computeOutcomeScore, recordIteration } from './outcome-score.js';
|
|
18
|
+
export { decomposeIntent, compareIntentObjects, } from './intent-decomposition.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/iole/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,OAAO,GACR,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Intent & Outcome Loop Engine
|
|
3
|
+
*
|
|
4
|
+
* Eliminates agent drift and stuck loops via deterministic feedback loops.
|
|
5
|
+
*
|
|
6
|
+
* Subsystems:
|
|
7
|
+
* - intent-signature: Derive stable hash from task prompt; detect drift
|
|
8
|
+
* - failure-vector: Parse test/build/trace failures into structured form
|
|
9
|
+
* - expansion-ladder: 4-level context escalation triggered by failures
|
|
10
|
+
* - outcome-score: Track pass rates, stability, improvement trends
|
|
11
|
+
*/
|
|
12
|
+
export { deriveIntentSignature, compareIntentSignatures, } from './intent-signature.js';
|
|
13
|
+
export { parseFailureVector } from './failure-vector.js';
|
|
14
|
+
export { initExpansionLadder, recordOutcome, getLevelParams, isStuck, } from './expansion-ladder.js';
|
|
15
|
+
export { computeOutcomeScore, recordIteration } from './outcome-score.js';
|
|
16
|
+
export { decomposeIntent, compareIntentObjects, } from './intent-decomposition.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iole/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,OAAO,GACR,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Intent Decomposition Engine
|
|
3
|
+
*
|
|
4
|
+
* Upgrades the intent signature to a fully structured IntentObject:
|
|
5
|
+
* { domain, operation, layer, entities, constraints }
|
|
6
|
+
*
|
|
7
|
+
* All extraction uses deterministic keyword parsing — no embeddings, no LLMs.
|
|
8
|
+
* Same task string → same IntentObject.
|
|
9
|
+
*
|
|
10
|
+
* Benefits over raw intent signature:
|
|
11
|
+
* - Smarter expansion ladder decisions (bug in routes layer → add route deps)
|
|
12
|
+
* - Better exemplar matching (feature in services → fetch service exemplar)
|
|
13
|
+
* - Reusable across sessions (IntentObjects can be compared structurally)
|
|
14
|
+
*/
|
|
15
|
+
import type { IntentObject } from '@codeledger/types';
|
|
16
|
+
/**
|
|
17
|
+
* Decompose a task string into a structured IntentObject.
|
|
18
|
+
*
|
|
19
|
+
* All extraction is deterministic keyword/regex parsing.
|
|
20
|
+
* Same task → same IntentObject (modulo timestamp).
|
|
21
|
+
*
|
|
22
|
+
* v2.1.1 additions:
|
|
23
|
+
* - `category`: deterministic "{domain}_{operation}" or "general_task" fallback
|
|
24
|
+
* - `intentConfidence`: 0–1 score reflecting extraction quality (low = ambiguous input)
|
|
25
|
+
*/
|
|
26
|
+
export declare function decomposeIntent(task: string): IntentObject;
|
|
27
|
+
/**
|
|
28
|
+
* Compare two IntentObjects for semantic similarity.
|
|
29
|
+
* Returns a score from 0 (completely different) to 1 (identical).
|
|
30
|
+
* Used by the expansion ladder to detect if intent shifted between iterations.
|
|
31
|
+
*/
|
|
32
|
+
export declare function compareIntentObjects(a: IntentObject, b: IntentObject): number;
|
|
33
|
+
//# sourceMappingURL=intent-decomposition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-decomposition.d.ts","sourceRoot":"","sources":["../../src/iole/intent-decomposition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AAuGzE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAmE1D;AA0DD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAiC7E"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Intent Decomposition Engine
|
|
3
|
+
*
|
|
4
|
+
* Upgrades the intent signature to a fully structured IntentObject:
|
|
5
|
+
* { domain, operation, layer, entities, constraints }
|
|
6
|
+
*
|
|
7
|
+
* All extraction uses deterministic keyword parsing — no embeddings, no LLMs.
|
|
8
|
+
* Same task string → same IntentObject.
|
|
9
|
+
*
|
|
10
|
+
* Benefits over raw intent signature:
|
|
11
|
+
* - Smarter expansion ladder decisions (bug in routes layer → add route deps)
|
|
12
|
+
* - Better exemplar matching (feature in services → fetch service exemplar)
|
|
13
|
+
* - Reusable across sessions (IntentObjects can be compared structurally)
|
|
14
|
+
*/
|
|
15
|
+
// ─── Domain Patterns ─────────────────────────────────────────────────────────
|
|
16
|
+
const DOMAIN_PATTERNS = [
|
|
17
|
+
[/\b(auth|authen|login|logout|jwt|token|session|oauth|permission|rbac)\b/i, 'auth'],
|
|
18
|
+
[/\b(api|endpoint|route|rest|graphql|grpc|handler|controller)\b/i, 'api'],
|
|
19
|
+
[/\b(db|database|sql|query|migration|schema|prisma|orm|mongo|postgres|mysql)\b/i, 'database'],
|
|
20
|
+
[/\b(ui|component|render|view|page|screen|frontend|react|vue|svelte)\b/i, 'ui'],
|
|
21
|
+
[/\b(payment|billing|stripe|invoice|subscription|checkout)\b/i, 'payments'],
|
|
22
|
+
[/\b(email|notification|smtp|sendgrid|webhook|event|message|queue)\b/i, 'messaging'],
|
|
23
|
+
[/\b(cache|redis|memory|performance|latency|throughput|speed)\b/i, 'performance'],
|
|
24
|
+
[/\b(deploy|ci|cd|docker|kubernetes|infra|pipeline|workflow)\b/i, 'infrastructure'],
|
|
25
|
+
[/\b(test|spec|coverage|mock|stub|fixture|assertion)\b/i, 'testing'],
|
|
26
|
+
[/\b(config|env|setting|flag|feature.flag|dotenv)\b/i, 'config'],
|
|
27
|
+
[/\b(log|logger|trace|telemetry|metric|monitor|observ)\b/i, 'observability'],
|
|
28
|
+
[/\b(search|index|elastic|solr|fulltext|filter|sort)\b/i, 'search'],
|
|
29
|
+
[/\b(file|upload|download|storage|s3|blob|asset|media)\b/i, 'storage'],
|
|
30
|
+
[/\b(security|crypto|encrypt|decrypt|hash|salt|secret|vulnerability)\b/i, 'security'],
|
|
31
|
+
];
|
|
32
|
+
// ─── Layer Patterns ───────────────────────────────────────────────────────────
|
|
33
|
+
const LAYER_PATTERNS = [
|
|
34
|
+
[/\b(type|interface|schema|model|entity|dto|struct)\b/i, 'types'],
|
|
35
|
+
[/\b(route|endpoint|handler|controller|resource)\b/i, 'routes'],
|
|
36
|
+
[/\b(service|business.logic|use.case|usecase|domain)\b/i, 'services'],
|
|
37
|
+
[/\b(test|spec|unit|integration|e2e|fixture)\b/i, 'tests'],
|
|
38
|
+
[/\b(config|setting|env|environment)\b/i, 'config'],
|
|
39
|
+
[/\b(infra|deploy|pipeline|migration|seed)\b/i, 'infra'],
|
|
40
|
+
[/\b(model|repository|dao|store|persist|storage)\b/i, 'models'],
|
|
41
|
+
];
|
|
42
|
+
// ─── Operation Patterns ───────────────────────────────────────────────────────
|
|
43
|
+
const OPERATION_PATTERNS = [
|
|
44
|
+
[/\b(fix|bug|error|crash|broken|fail|issue|regression|resolve|debug)\b/i, 'bugfix'],
|
|
45
|
+
[/\b(add|create|implement|new|build|introduce|feature|extend|support)\b/i, 'feature'],
|
|
46
|
+
[/\b(refactor|extract|cleanup|rename|reorganize|simplify|move|restructure)\b/i, 'refactor'],
|
|
47
|
+
[/\b(test|spec|coverage|assertion|mock|vitest|jest)\b/i, 'test_update'],
|
|
48
|
+
[/\b(config|env|setting|env.var|deploy|ci|yaml|toml|json)\b/i, 'config'],
|
|
49
|
+
];
|
|
50
|
+
// ─── Constraint Patterns ──────────────────────────────────────────────────────
|
|
51
|
+
const CONSTRAINT_PATTERNS = [
|
|
52
|
+
[/\bno\s+breaking\s+change/i, 'no breaking changes'],
|
|
53
|
+
[/\bbackward.compat/i, 'maintain backward compatibility'],
|
|
54
|
+
[/\btype.safe/i, 'must be type-safe'],
|
|
55
|
+
[/\bno\s+migration/i, 'no database migration'],
|
|
56
|
+
[/\bperformance/i, 'preserve performance'],
|
|
57
|
+
[/\bsecurity/i, 'must not introduce security issues'],
|
|
58
|
+
[/\btest\s+must\s+pass/i, 'all tests must pass'],
|
|
59
|
+
[/\bno\s+new\s+dep/i, 'no new dependencies'],
|
|
60
|
+
[/\bminimal\s+change/i, 'minimal diff'],
|
|
61
|
+
];
|
|
62
|
+
// ─── Entity Extraction ────────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Extract specific named entities from a task string.
|
|
65
|
+
* Looks for: PascalCase names, camelCase identifiers, quoted strings,
|
|
66
|
+
* kebab-case file names, and explicit function/class references.
|
|
67
|
+
*/
|
|
68
|
+
function extractEntities(task) {
|
|
69
|
+
const entities = new Set();
|
|
70
|
+
// PascalCase (likely type/class names): AuthMiddleware, UserService
|
|
71
|
+
const pascalRe = /\b([A-Z][a-z]+(?:[A-Z][a-z]+)+)\b/g;
|
|
72
|
+
let m;
|
|
73
|
+
while ((m = pascalRe.exec(task)) !== null) {
|
|
74
|
+
entities.add(m[1]);
|
|
75
|
+
}
|
|
76
|
+
// camelCase identifiers: validateToken, getUserById
|
|
77
|
+
const camelRe = /\b([a-z][a-z]+[A-Z][a-zA-Z]+)\b/g;
|
|
78
|
+
while ((m = camelRe.exec(task)) !== null) {
|
|
79
|
+
if (m[1].length > 4)
|
|
80
|
+
entities.add(m[1]); // filter out very short camelCase
|
|
81
|
+
}
|
|
82
|
+
// Quoted strings: "auth middleware", 'user service'
|
|
83
|
+
const quotedRe = /['"]([^'"]{3,40})['"]/g;
|
|
84
|
+
while ((m = quotedRe.exec(task)) !== null) {
|
|
85
|
+
entities.add(m[1].trim());
|
|
86
|
+
}
|
|
87
|
+
// File-like references: auth.service.ts, user.controller.ts
|
|
88
|
+
const fileRe = /\b([\w-]+\.[tj]sx?)\b/g;
|
|
89
|
+
while ((m = fileRe.exec(task)) !== null) {
|
|
90
|
+
entities.add(m[1]);
|
|
91
|
+
}
|
|
92
|
+
// snake_case: validate_token, get_user_by_id
|
|
93
|
+
const snakeRe = /\b([a-z]{2,}(?:_[a-z]+){2,})\b/g;
|
|
94
|
+
while ((m = snakeRe.exec(task)) !== null) {
|
|
95
|
+
entities.add(m[1]);
|
|
96
|
+
}
|
|
97
|
+
return [...entities].slice(0, 10); // cap at 10 entities
|
|
98
|
+
}
|
|
99
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
100
|
+
/**
|
|
101
|
+
* Decompose a task string into a structured IntentObject.
|
|
102
|
+
*
|
|
103
|
+
* All extraction is deterministic keyword/regex parsing.
|
|
104
|
+
* Same task → same IntentObject (modulo timestamp).
|
|
105
|
+
*
|
|
106
|
+
* v2.1.1 additions:
|
|
107
|
+
* - `category`: deterministic "{domain}_{operation}" or "general_task" fallback
|
|
108
|
+
* - `intentConfidence`: 0–1 score reflecting extraction quality (low = ambiguous input)
|
|
109
|
+
*/
|
|
110
|
+
export function decomposeIntent(task) {
|
|
111
|
+
const lower = task.toLowerCase();
|
|
112
|
+
// Domain
|
|
113
|
+
let domain = 'general';
|
|
114
|
+
let domainMatched = false;
|
|
115
|
+
for (const [pattern, name] of DOMAIN_PATTERNS) {
|
|
116
|
+
if (pattern.test(lower)) {
|
|
117
|
+
domain = name;
|
|
118
|
+
domainMatched = true;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Operation
|
|
123
|
+
let operation = 'unknown';
|
|
124
|
+
let operationMatched = false;
|
|
125
|
+
for (const [pattern, op] of OPERATION_PATTERNS) {
|
|
126
|
+
if (pattern.test(lower)) {
|
|
127
|
+
operation = op;
|
|
128
|
+
operationMatched = true;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Layer
|
|
133
|
+
let layer = 'unknown';
|
|
134
|
+
let layerMatched = false;
|
|
135
|
+
for (const [pattern, l] of LAYER_PATTERNS) {
|
|
136
|
+
if (pattern.test(lower)) {
|
|
137
|
+
layer = l;
|
|
138
|
+
layerMatched = true;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Entities
|
|
143
|
+
const entities = extractEntities(task);
|
|
144
|
+
// Constraints
|
|
145
|
+
const constraints = [];
|
|
146
|
+
for (const [pattern, constraint] of CONSTRAINT_PATTERNS) {
|
|
147
|
+
if (pattern.test(task)) {
|
|
148
|
+
constraints.push(constraint);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Category: deterministic "{domain}_{operation}"; fallback when either is ambiguous
|
|
152
|
+
const category = deriveCategory(domain, operation, domainMatched, operationMatched);
|
|
153
|
+
// Intent confidence: fraction of extraction passes that produced a specific result
|
|
154
|
+
// (not falling back to default). Low confidence = ambiguous prompt.
|
|
155
|
+
const intentConfidence = computeIntentConfidence(domainMatched, operationMatched, layerMatched, entities.length);
|
|
156
|
+
return {
|
|
157
|
+
domain,
|
|
158
|
+
operation,
|
|
159
|
+
layer,
|
|
160
|
+
entities,
|
|
161
|
+
constraints,
|
|
162
|
+
category,
|
|
163
|
+
intentConfidence,
|
|
164
|
+
raw_task: task,
|
|
165
|
+
decomposed_at: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// ─── Category Derivation ──────────────────────────────────────────────────────
|
|
169
|
+
/**
|
|
170
|
+
* Derive the aggregation category from domain + operation.
|
|
171
|
+
* Falls back to "general_task" when either is unknown/general.
|
|
172
|
+
*
|
|
173
|
+
* Examples: auth + bugfix → "auth_bugfix", api + feature → "api_feature"
|
|
174
|
+
*/
|
|
175
|
+
function deriveCategory(domain, operation, domainMatched, operationMatched) {
|
|
176
|
+
// Both specific → concrete category (enables meaningful history aggregation)
|
|
177
|
+
if (domainMatched && operationMatched) {
|
|
178
|
+
return `${domain}_${operation}`;
|
|
179
|
+
}
|
|
180
|
+
// Domain known, operation unknown → partial category (still useful for aggregation)
|
|
181
|
+
if (domainMatched && !operationMatched) {
|
|
182
|
+
return `${domain}_task`;
|
|
183
|
+
}
|
|
184
|
+
// Operation known, domain unknown → operation-level fallback
|
|
185
|
+
if (!domainMatched && operationMatched) {
|
|
186
|
+
return `general_${operation}`;
|
|
187
|
+
}
|
|
188
|
+
// Neither matched → generic fallback
|
|
189
|
+
return 'general_task';
|
|
190
|
+
}
|
|
191
|
+
// ─── Intent Confidence ────────────────────────────────────────────────────────
|
|
192
|
+
/**
|
|
193
|
+
* Compute extraction confidence as a weighted fraction of signals that fired.
|
|
194
|
+
*
|
|
195
|
+
* Scoring:
|
|
196
|
+
* - Domain match : 0.35 (most important — determines context area)
|
|
197
|
+
* - Operation match : 0.35 (determines what to do)
|
|
198
|
+
* - Layer match : 0.15 (narrows architectural scope)
|
|
199
|
+
* - Entities found : 0.15 (presence of specific names increases confidence)
|
|
200
|
+
*/
|
|
201
|
+
function computeIntentConfidence(domainMatched, operationMatched, layerMatched, entityCount) {
|
|
202
|
+
let score = 0;
|
|
203
|
+
if (domainMatched)
|
|
204
|
+
score += 0.35;
|
|
205
|
+
if (operationMatched)
|
|
206
|
+
score += 0.35;
|
|
207
|
+
if (layerMatched)
|
|
208
|
+
score += 0.15;
|
|
209
|
+
// Entities: at least 1 → full 0.15; 0 → 0
|
|
210
|
+
if (entityCount > 0)
|
|
211
|
+
score += 0.15;
|
|
212
|
+
return score; // already [0,1] by construction
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Compare two IntentObjects for semantic similarity.
|
|
216
|
+
* Returns a score from 0 (completely different) to 1 (identical).
|
|
217
|
+
* Used by the expansion ladder to detect if intent shifted between iterations.
|
|
218
|
+
*/
|
|
219
|
+
export function compareIntentObjects(a, b) {
|
|
220
|
+
let score = 0;
|
|
221
|
+
let total = 0;
|
|
222
|
+
// Domain match (high weight)
|
|
223
|
+
total += 3;
|
|
224
|
+
if (a.domain === b.domain)
|
|
225
|
+
score += 3;
|
|
226
|
+
// Operation match
|
|
227
|
+
total += 2;
|
|
228
|
+
if (a.operation === b.operation)
|
|
229
|
+
score += 2;
|
|
230
|
+
// Layer match
|
|
231
|
+
total += 2;
|
|
232
|
+
if (a.layer === b.layer)
|
|
233
|
+
score += 2;
|
|
234
|
+
// Entity overlap (Jaccard on entity sets)
|
|
235
|
+
total += 2;
|
|
236
|
+
const aEnts = new Set(a.entities.map((e) => e.toLowerCase()));
|
|
237
|
+
const bEnts = new Set(b.entities.map((e) => e.toLowerCase()));
|
|
238
|
+
const intersection = [...aEnts].filter((e) => bEnts.has(e)).length;
|
|
239
|
+
const union = new Set([...aEnts, ...bEnts]).size;
|
|
240
|
+
if (union > 0)
|
|
241
|
+
score += 2 * (intersection / union);
|
|
242
|
+
// Constraint overlap
|
|
243
|
+
total += 1;
|
|
244
|
+
const aConst = new Set(a.constraints);
|
|
245
|
+
const bConst = new Set(b.constraints);
|
|
246
|
+
const constIntersect = [...aConst].filter((c) => bConst.has(c)).length;
|
|
247
|
+
const constUnion = new Set([...aConst, ...bConst]).size;
|
|
248
|
+
if (constUnion > 0)
|
|
249
|
+
score += constIntersect / constUnion;
|
|
250
|
+
return total > 0 ? score / total : 0;
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=intent-decomposition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-decomposition.js","sourceRoot":"","sources":["../../src/iole/intent-decomposition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,gFAAgF;AAEhF,MAAM,eAAe,GAA4B;IAC/C,CAAC,yEAAyE,EAAE,MAAM,CAAC;IACnF,CAAC,gEAAgE,EAAE,KAAK,CAAC;IACzE,CAAC,+EAA+E,EAAE,UAAU,CAAC;IAC7F,CAAC,uEAAuE,EAAE,IAAI,CAAC;IAC/E,CAAC,6DAA6D,EAAE,UAAU,CAAC;IAC3E,CAAC,qEAAqE,EAAE,WAAW,CAAC;IACpF,CAAC,gEAAgE,EAAE,aAAa,CAAC;IACjF,CAAC,+DAA+D,EAAE,gBAAgB,CAAC;IACnF,CAAC,uDAAuD,EAAE,SAAS,CAAC;IACpE,CAAC,oDAAoD,EAAE,QAAQ,CAAC;IAChE,CAAC,yDAAyD,EAAE,eAAe,CAAC;IAC5E,CAAC,uDAAuD,EAAE,QAAQ,CAAC;IACnE,CAAC,yDAAyD,EAAE,SAAS,CAAC;IACtE,CAAC,uEAAuE,EAAE,UAAU,CAAC;CACtF,CAAC;AAEF,iFAAiF;AAEjF,MAAM,cAAc,GAAuC;IACzD,CAAC,sDAAsD,EAAE,OAAO,CAAC;IACjE,CAAC,mDAAmD,EAAE,QAAQ,CAAC;IAC/D,CAAC,uDAAuD,EAAE,UAAU,CAAC;IACrE,CAAC,+CAA+C,EAAE,OAAO,CAAC;IAC1D,CAAC,uCAAuC,EAAE,QAAQ,CAAC;IACnD,CAAC,6CAA6C,EAAE,OAAO,CAAC;IACxD,CAAC,mDAAmD,EAAE,QAAQ,CAAC;CAChE,CAA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ACrB,KAAK,IAAI,CAAC,CAAC;IACX,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACtC,MAAM,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,IAAI,UAAU,GAAG,CAAC;QAAE,KAAK,IAAI,cAAc,GAAG,UAAU,CAAC;IAEzD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOLE — Intent Signature
|
|
3
|
+
*
|
|
4
|
+
* Derives a stable, deterministic hash from a task prompt and optional
|
|
5
|
+
* CLI parameters. Used to detect intent drift across iterations and
|
|
6
|
+
* to correlate outcomes with their originating intent.
|
|
7
|
+
*
|
|
8
|
+
* Deterministic: same task string → same signature.
|
|
9
|
+
*/
|
|
10
|
+
import type { IntentSignature } from '@codeledger/types';
|
|
11
|
+
/**
|
|
12
|
+
* Derive a deterministic IntentSignature from a task description.
|
|
13
|
+
*
|
|
14
|
+
* The signature includes:
|
|
15
|
+
* - A stable hash (SHA-256 truncated to 16 hex chars)
|
|
16
|
+
* - Normalized task keywords (lowercased, de-duped, sorted)
|
|
17
|
+
* - Inferred task category (bug_fix, feature_add, refactor, test_update, config, unknown)
|
|
18
|
+
* - Timestamp of derivation
|
|
19
|
+
*/
|
|
20
|
+
export declare function deriveIntentSignature(task: string, params?: Record<string, string>): IntentSignature;
|
|
21
|
+
/**
|
|
22
|
+
* Compare two intent signatures to detect drift.
|
|
23
|
+
*
|
|
24
|
+
* Returns a DriftLevel:
|
|
25
|
+
* - 'none' → same hash (identical intent)
|
|
26
|
+
* - 'minor' → same category, similar keywords (Jaccard ≥ 0.6)
|
|
27
|
+
* - 'major' → same category, diverged keywords (Jaccard 0.3–0.6)
|
|
28
|
+
* - 'critical' → different category or Jaccard < 0.3
|
|
29
|
+
*/
|
|
30
|
+
export declare function compareIntentSignatures(a: IntentSignature, b: IntentSignature): IntentDriftResult;
|
|
31
|
+
export type IntentDriftLevel = 'none' | 'minor' | 'major' | 'critical';
|
|
32
|
+
export interface IntentDriftResult {
|
|
33
|
+
level: IntentDriftLevel;
|
|
34
|
+
jaccard: number;
|
|
35
|
+
category_changed: boolean;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=intent-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-signature.d.ts","sourceRoot":"","sources":["../../src/iole/intent-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIzD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAClC,eAAe,CAoBjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,CAAC,EAAE,eAAe,EAClB,CAAC,EAAE,eAAe,GACjB,iBAAiB,CAkBnB;AAqDD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AAEvE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;CAC3B"}
|