zero-config-cli-bridge 1.1.0 → 1.2.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/executor.d.ts.map +1 -1
- package/dist/executor.js +10 -9
- package/dist/executor.js.map +1 -1
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +6 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +43 -41
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
package/dist/executor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAcD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAgClF"}
|
package/dist/executor.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
2
|
+
// stdout carries structured JSON — large ceiling so index.ts can apply item-level truncation.
|
|
3
|
+
const MAX_STDOUT_CHARS = 2_000_000; // 2 MB
|
|
4
|
+
// stderr carries error messages and probe text — keep tight.
|
|
5
|
+
const MAX_STDERR_CHARS = 4_096;
|
|
6
|
+
const RAW_TRUNCATION_MSG = '\n...[Output truncated. Use grep/jq to filter]';
|
|
6
7
|
const TIMEOUT_MS = 15_000;
|
|
7
|
-
function truncate(s) {
|
|
8
|
-
if (s.length <=
|
|
8
|
+
function truncate(s, limit) {
|
|
9
|
+
if (s.length <= limit)
|
|
9
10
|
return s;
|
|
10
|
-
return s.slice(0,
|
|
11
|
+
return s.slice(0, limit) + RAW_TRUNCATION_MSG;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Executes a binary directly with an args array.
|
|
@@ -30,8 +31,8 @@ export function executeCommand(bin, args) {
|
|
|
30
31
|
proc.on('close', (code) => {
|
|
31
32
|
clearTimeout(timer);
|
|
32
33
|
resolve({
|
|
33
|
-
stdout: truncate(stdoutBuf),
|
|
34
|
-
stderr: truncate(stderrBuf),
|
|
34
|
+
stdout: truncate(stdoutBuf, MAX_STDOUT_CHARS),
|
|
35
|
+
stderr: truncate(stderrBuf, MAX_STDERR_CHARS),
|
|
35
36
|
exitCode: code ?? 1,
|
|
36
37
|
});
|
|
37
38
|
});
|
package/dist/executor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC,
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC,8FAA8F;AAC9F,MAAM,gBAAgB,GAAG,SAAS,CAAC,CAAC,OAAO;AAC3C,6DAA6D;AAC7D,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,kBAAkB,GAAG,gDAAgD,CAAC;AAC5E,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,SAAS,QAAQ,CAAC,CAAS,EAAE,KAAa;IACxC,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,CAAC,CAAC;IA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AAC,SAAS,EAAE,gBAAgB,CAAC;gBAC7C,QAAQ,EAAE,IAAI,IAAI,CAAC;aACpB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YAC9B,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,25 +4,36 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { executeCommand } from './executor.js';
|
|
6
6
|
const MAX_JSON_ITEMS = 30;
|
|
7
|
-
const
|
|
7
|
+
const JSON_TRUNCATION_MSG = `\n...[Output truncated at ${MAX_JSON_ITEMS} items. Use --limit or filters to narrow results.]`;
|
|
8
|
+
const MAX_TEXT_CHARS = 2000;
|
|
9
|
+
const TEXT_TRUNCATION_MSG = '\n...[Output truncated. Use grep/jq to filter]';
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* Normalises command output for LLM consumption.
|
|
12
|
+
*
|
|
13
|
+
* JSON path : caps array at MAX_JSON_ITEMS — always returns valid JSON.
|
|
14
|
+
* Text path : caps at MAX_TEXT_CHARS — prevents context exhaustion on
|
|
15
|
+
* error messages and plain-text fallback output.
|
|
16
|
+
*
|
|
17
|
+
* The executor's MAX_RAW_CHARS (4096) is an independent backstop that fires
|
|
18
|
+
* only if this function is somehow bypassed (e.g. future code paths).
|
|
12
19
|
*/
|
|
13
|
-
function
|
|
20
|
+
function toSafeOutput(raw) {
|
|
14
21
|
try {
|
|
15
22
|
const parsed = JSON.parse(raw);
|
|
16
23
|
if (Array.isArray(parsed)) {
|
|
17
24
|
if (parsed.length > MAX_JSON_ITEMS) {
|
|
18
|
-
return JSON.stringify(parsed.slice(0, MAX_JSON_ITEMS), null, 2) +
|
|
25
|
+
return JSON.stringify(parsed.slice(0, MAX_JSON_ITEMS), null, 2) + JSON_TRUNCATION_MSG;
|
|
19
26
|
}
|
|
20
27
|
return JSON.stringify(parsed, null, 2);
|
|
21
28
|
}
|
|
22
29
|
return JSON.stringify(parsed, null, 2);
|
|
23
30
|
}
|
|
24
31
|
catch {
|
|
25
|
-
|
|
32
|
+
// Non-JSON: error messages, plain text — apply character cap
|
|
33
|
+
if (raw.length > MAX_TEXT_CHARS) {
|
|
34
|
+
return raw.slice(0, MAX_TEXT_CHARS) + TEXT_TRUNCATION_MSG;
|
|
35
|
+
}
|
|
36
|
+
return raw;
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
import { validateSubcommand, validateArgs } from './security.js';
|
|
@@ -70,7 +81,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
70
81
|
};
|
|
71
82
|
}
|
|
72
83
|
const raw = result.stdout || result.stderr || `(no output, exit code ${result.exitCode})`;
|
|
73
|
-
const output =
|
|
84
|
+
const output = toSafeOutput(raw);
|
|
74
85
|
return {
|
|
75
86
|
content: [{ type: 'text', text: output }],
|
|
76
87
|
isError: result.exitCode !== 0,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sour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GAAG,MAAM,oBAAoB,EAAE,CAAC;IAC3C,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtD,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -11,10 +11,14 @@ export interface ToolDefinition {
|
|
|
11
11
|
};
|
|
12
12
|
/** gh subcommand tokens, e.g. ['issue', 'list'] */
|
|
13
13
|
subcommand: string[];
|
|
14
|
-
/** JSON fields confirmed available in the local gh binary */
|
|
14
|
+
/** JSON fields confirmed available in the local gh binary, filtered to repo-scope-safe set */
|
|
15
15
|
jsonFields: string[];
|
|
16
16
|
}
|
|
17
17
|
export declare function buildToolDefinitions(): Promise<ToolDefinition[]>;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Builds the gh args array using --flag=value notation throughout.
|
|
20
|
+
* This prevents option injection: a value starting with '-' cannot
|
|
21
|
+
* be misinterpreted as a separate flag by gh's argument parser.
|
|
22
|
+
*/
|
|
19
23
|
export declare function buildGhArgs(tool: ToolDefinition, args: Record<string, unknown>): string[];
|
|
20
24
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,mDAAmD;IACnD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,mDAAmD;IACnD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,8FAA8F;IAC9F,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAoDD,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CA8CtE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAWzF"}
|
package/dist/schema.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { executeCommand } from './executor.js';
|
|
2
|
-
const FALLBACK_FIELDS = {
|
|
3
|
-
'issue list': ['number', 'title', 'state', 'labels', 'assignees', 'createdAt', 'url'],
|
|
4
|
-
'pr list': ['number', 'title', 'state', 'labels', 'assignees', 'createdAt', 'url', 'baseRefName'],
|
|
5
|
-
};
|
|
6
2
|
/**
|
|
7
|
-
* Fields
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* - `body`
|
|
3
|
+
* Fields requiring only the standard `repo` OAuth scope.
|
|
4
|
+
* Explicitly excludes:
|
|
5
|
+
* - `id` — requires read:project scope
|
|
6
|
+
* - `body` — unbounded text; breaks JSON item-level truncation
|
|
11
7
|
*/
|
|
12
8
|
const REPO_SCOPE_SAFE_FIELDS = new Set([
|
|
13
9
|
'number', 'title', 'state', 'labels', 'assignees',
|
|
@@ -17,51 +13,52 @@ const REPO_SCOPE_SAFE_FIELDS = new Set([
|
|
|
17
13
|
'baseRefName', 'headRefName', 'headRepository', 'mergedAt', 'mergeCommit',
|
|
18
14
|
'reviewDecision', 'additions', 'deletions', 'changedFiles',
|
|
19
15
|
]);
|
|
16
|
+
const FALLBACK_FIELDS = {
|
|
17
|
+
'issue list': ['number', 'title', 'state', 'labels', 'assignees', 'createdAt', 'url'],
|
|
18
|
+
'pr list': ['number', 'title', 'state', 'labels', 'assignees', 'createdAt', 'url', 'baseRefName'],
|
|
19
|
+
};
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* subcommand
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Falls back to a known-safe static list if detection fails.
|
|
21
|
+
* Detects JSON fields available in the local gh binary by calling
|
|
22
|
+
* `gh <subcommand> --json` with no field argument. Recent gh versions
|
|
23
|
+
* output the available field list to stderr in this case — no error
|
|
24
|
+
* injection needed. Falls back to the static list on any failure.
|
|
26
25
|
*/
|
|
27
|
-
async function
|
|
26
|
+
async function detectJsonFields(subcommand) {
|
|
28
27
|
const key = subcommand.join(' ');
|
|
29
28
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const fields = match[1]
|
|
41
|
-
.trim()
|
|
42
|
-
.split(/[\s,]+/)
|
|
29
|
+
// `gh issue list --json` with no fields causes gh to list available fields on stderr.
|
|
30
|
+
// This is documented behaviour, not error scraping.
|
|
31
|
+
const result = await executeCommand('gh', [...subcommand, '--json']);
|
|
32
|
+
const text = result.stderr + result.stdout;
|
|
33
|
+
// Output format: "Use `--json` with one or more of: field1,field2,..."
|
|
34
|
+
// or a newline-separated list after "Available fields:"
|
|
35
|
+
const commaMatch = text.match(/--json`?\s+with[^:]*:\s*([a-zA-Z,\s]+)/i);
|
|
36
|
+
if (commaMatch) {
|
|
37
|
+
const fields = commaMatch[1]
|
|
38
|
+
.split(/[,\s]+/)
|
|
43
39
|
.map((f) => f.trim())
|
|
44
40
|
.filter((f) => /^[a-zA-Z][a-zA-Z0-9]*$/.test(f))
|
|
45
|
-
.filter((f) => REPO_SCOPE_SAFE_FIELDS.has(f));
|
|
41
|
+
.filter((f) => REPO_SCOPE_SAFE_FIELDS.has(f));
|
|
46
42
|
if (fields.length > 0)
|
|
47
43
|
return fields;
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
catch {
|
|
51
|
-
// gh not
|
|
47
|
+
// gh not installed or timed out
|
|
52
48
|
}
|
|
53
49
|
return FALLBACK_FIELDS[key] ?? [];
|
|
54
50
|
}
|
|
55
51
|
export async function buildToolDefinitions() {
|
|
56
52
|
const [issueFields, prFields] = await Promise.all([
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
detectJsonFields(['issue', 'list']),
|
|
54
|
+
detectJsonFields(['pr', 'list']),
|
|
59
55
|
]);
|
|
60
56
|
return [
|
|
61
57
|
{
|
|
62
58
|
name: 'gh_issue_list',
|
|
63
59
|
description: 'List GitHub issues as structured JSON. ' +
|
|
64
|
-
'Uses the local `gh` CLI and its existing authentication — no API key required.'
|
|
60
|
+
'Uses the local `gh` CLI and its existing authentication — no API key required. ' +
|
|
61
|
+
'Read-only. Does not create, edit, or delete issues.',
|
|
65
62
|
subcommand: ['issue', 'list'],
|
|
66
63
|
jsonFields: issueFields,
|
|
67
64
|
inputSchema: {
|
|
@@ -78,7 +75,8 @@ export async function buildToolDefinitions() {
|
|
|
78
75
|
{
|
|
79
76
|
name: 'gh_pr_list',
|
|
80
77
|
description: 'List GitHub pull requests as structured JSON. ' +
|
|
81
|
-
'Uses the local `gh` CLI and its existing authentication — no API key required.'
|
|
78
|
+
'Uses the local `gh` CLI and its existing authentication — no API key required. ' +
|
|
79
|
+
'Read-only. Does not create, edit, merge, or close pull requests.',
|
|
82
80
|
subcommand: ['pr', 'list'],
|
|
83
81
|
jsonFields: prFields,
|
|
84
82
|
inputSchema: {
|
|
@@ -94,21 +92,25 @@ export async function buildToolDefinitions() {
|
|
|
94
92
|
},
|
|
95
93
|
];
|
|
96
94
|
}
|
|
97
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Builds the gh args array using --flag=value notation throughout.
|
|
97
|
+
* This prevents option injection: a value starting with '-' cannot
|
|
98
|
+
* be misinterpreted as a separate flag by gh's argument parser.
|
|
99
|
+
*/
|
|
98
100
|
export function buildGhArgs(tool, args) {
|
|
99
|
-
const parts = [...tool.subcommand,
|
|
101
|
+
const parts = [...tool.subcommand, `--json=${tool.jsonFields.join(',')}`];
|
|
100
102
|
if (args['repo'] !== undefined)
|
|
101
|
-
parts.push(
|
|
103
|
+
parts.push(`--repo=${String(args['repo'])}`);
|
|
102
104
|
if (args['limit'] !== undefined)
|
|
103
|
-
parts.push(
|
|
105
|
+
parts.push(`--limit=${String(args['limit'])}`);
|
|
104
106
|
if (args['state'] !== undefined)
|
|
105
|
-
parts.push(
|
|
107
|
+
parts.push(`--state=${String(args['state'])}`);
|
|
106
108
|
if (args['label'] !== undefined && tool.name === 'gh_issue_list')
|
|
107
|
-
parts.push(
|
|
109
|
+
parts.push(`--label=${String(args['label'])}`);
|
|
108
110
|
if (args['assignee'] !== undefined)
|
|
109
|
-
parts.push(
|
|
111
|
+
parts.push(`--assignee=${String(args['assignee'])}`);
|
|
110
112
|
if (args['base'] !== undefined && tool.name === 'gh_pr_list')
|
|
111
|
-
parts.push(
|
|
113
|
+
parts.push(`--base=${String(args['base'])}`);
|
|
112
114
|
return parts;
|
|
113
115
|
}
|
|
114
116
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgB/C,MAAM,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgB/C;;;;;GAKG;AACH,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC;IAC1D,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW;IACjD,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK;IACrD,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ;IAC5C,cAAc;IACd,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa;IACzE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc;CAC3D,CAAC,CAAC;AAEH,MAAM,eAAe,GAA6B;IAChD,YAAY,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC;IACrF,SAAS,EAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,CAAC;CACrG,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAC,UAAoB;IAClD,MAAM,GAAG,GAAG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