@inhuman.tools/policy-bash-disassembler 0.0.0-stage → 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/LICENSE.md +7 -0
- package/dist/identity.d.ts +8 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +29 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/peel-cwd.d.ts +9 -0
- package/dist/peel-cwd.d.ts.map +1 -0
- package/dist/peel-cwd.js +120 -0
- package/dist/peel-cwd.js.map +1 -0
- package/dist/prep.d.ts +61 -0
- package/dist/prep.d.ts.map +1 -0
- package/dist/prep.js +718 -0
- package/dist/prep.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -3
- package/src/identity.ts +27 -0
- package/src/index.ts +3 -0
- package/src/peel-cwd.ts +112 -0
- package/src/prep.ts +850 -0
- package/src/types.ts +10 -0
- package/README.md +0 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 Merkle Bonsai
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-form argv0 is a known command only when `which` returns the same path.
|
|
3
|
+
* Otherwise the token stays a path.
|
|
4
|
+
*/
|
|
5
|
+
export type Which = (name: string) => string | undefined;
|
|
6
|
+
/** Named `cmd` is itself. Path-form is `cmd` only when `which` agrees. */
|
|
7
|
+
export declare function resolveKnown(raw: string, known: ReadonlySet<string>, which: Which | undefined): string | undefined;
|
|
8
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAEzD,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAUlH"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-form argv0 is a known command only when `which` returns the same path.
|
|
3
|
+
* Otherwise the token stays a path.
|
|
4
|
+
*/
|
|
5
|
+
/** Named `cmd` is itself. Path-form is `cmd` only when `which` agrees. */
|
|
6
|
+
export function resolveKnown(raw, known, which) {
|
|
7
|
+
const slash = raw.lastIndexOf("/");
|
|
8
|
+
const base = slash === -1 ? raw : raw.slice(slash + 1) || raw;
|
|
9
|
+
if (base === "" || !known.has(base))
|
|
10
|
+
return undefined;
|
|
11
|
+
if (!raw.includes("/"))
|
|
12
|
+
return base;
|
|
13
|
+
const canonical = which?.(base);
|
|
14
|
+
if (canonical === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const left = normalizeIdentity(raw);
|
|
17
|
+
const right = normalizeIdentity(canonical);
|
|
18
|
+
return left !== undefined && left === right ? base : undefined;
|
|
19
|
+
}
|
|
20
|
+
function normalizeIdentity(raw) {
|
|
21
|
+
if (raw === "" || raw.includes("\0"))
|
|
22
|
+
return undefined;
|
|
23
|
+
const slash = raw.replaceAll("\\", "/");
|
|
24
|
+
const parts = slash.split("/").filter((seg) => seg !== "" && seg !== ".");
|
|
25
|
+
if (parts.includes(".."))
|
|
26
|
+
return undefined;
|
|
27
|
+
return slash.startsWith("/") ? `/${parts.join("/")}` : parts.join("/");
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,0EAA0E;AAC1E,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,KAA0B,EAAE,KAAwB;IAC5F,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;IAC9D,IAAI,IAAI,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACtD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC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ist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type PeeledCd = {
|
|
2
|
+
readonly cwd: string;
|
|
3
|
+
readonly command: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function peelLeadingCd(source: string): PeeledCd | null;
|
|
6
|
+
/** Keep an explicit `cwd` arg when it names the same leaf; never override a disagreement. */
|
|
7
|
+
export declare function peelShellCwd(command: string, cwdArg?: string): PeeledCd | null;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=peel-cwd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peel-cwd.d.ts","sourceRoot":"","sources":["../src/peel-cwd.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAyB7D;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAU9E"}
|
package/dist/peel-cwd.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peel a leading cwd-only `cd` off a shell command into the `cwd` arg.
|
|
3
|
+
* Unbash AST, not regex. Quoted `;` is not a splitter. Remainder stays
|
|
4
|
+
* one `/bin/sh -c` — this is not execute-split.
|
|
5
|
+
*
|
|
6
|
+
* Peel only the first top-level list element (`&&` or `;` / newline).
|
|
7
|
+
* `||`, pipes, subshells, brace groups, `cd` that is not first, and
|
|
8
|
+
* `cd` with flags/extra operands stay on the command string.
|
|
9
|
+
*/
|
|
10
|
+
import { parse } from "unbash";
|
|
11
|
+
const PARTLESS_FORBIDDEN = /[*?[\\$`]/;
|
|
12
|
+
export function peelLeadingCd(source) {
|
|
13
|
+
const script = parse(source);
|
|
14
|
+
if (script.errors !== undefined && script.errors.length > 0)
|
|
15
|
+
return null;
|
|
16
|
+
const statements = script.commands;
|
|
17
|
+
if (statements.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
const first = statements[0];
|
|
20
|
+
if (first === undefined || first.background === true || first.redirects.length > 0)
|
|
21
|
+
return null;
|
|
22
|
+
const node = first.command;
|
|
23
|
+
const simple = asSimpleCommand(node);
|
|
24
|
+
if (simple !== null) {
|
|
25
|
+
const cwd = cwdOnlyPath(simple);
|
|
26
|
+
if (cwd === null)
|
|
27
|
+
return null;
|
|
28
|
+
if (statements.length === 1)
|
|
29
|
+
return { cwd, command: "" };
|
|
30
|
+
return { cwd, command: source.slice(statements[1].pos).trim() };
|
|
31
|
+
}
|
|
32
|
+
if (node.type !== "AndOr" || node.operators[0] !== "&&")
|
|
33
|
+
return null;
|
|
34
|
+
const head = asSimpleCommand(node.commands[0]);
|
|
35
|
+
if (head === null)
|
|
36
|
+
return null;
|
|
37
|
+
const cwd = cwdOnlyPath(head);
|
|
38
|
+
if (cwd === null)
|
|
39
|
+
return null;
|
|
40
|
+
const rest = node.commands[1];
|
|
41
|
+
if (rest === undefined)
|
|
42
|
+
return { cwd, command: "" };
|
|
43
|
+
return { cwd, command: source.slice(rest.pos).trim() };
|
|
44
|
+
}
|
|
45
|
+
/** Keep an explicit `cwd` arg when it names the same leaf; never override a disagreement. */
|
|
46
|
+
export function peelShellCwd(command, cwdArg) {
|
|
47
|
+
const peeled = peelLeadingCd(command);
|
|
48
|
+
if (peeled === null)
|
|
49
|
+
return null;
|
|
50
|
+
if (cwdArg !== undefined && cwdArg !== "" && normalizeCwdToken(cwdArg) !== normalizeCwdToken(peeled.cwd)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
cwd: cwdArg !== undefined && cwdArg !== "" ? cwdArg : peeled.cwd,
|
|
55
|
+
command: peeled.command,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function normalizeCwdToken(raw) {
|
|
59
|
+
let token = raw.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
60
|
+
if (token.startsWith("./"))
|
|
61
|
+
token = token.slice(2);
|
|
62
|
+
return token === "" ? "." : token;
|
|
63
|
+
}
|
|
64
|
+
function asSimpleCommand(node) {
|
|
65
|
+
if (node === undefined)
|
|
66
|
+
return null;
|
|
67
|
+
if (node.type === "Command")
|
|
68
|
+
return node;
|
|
69
|
+
if (node.type !== "Pipeline")
|
|
70
|
+
return null;
|
|
71
|
+
if (node.commands.length !== 1 || (node.operators?.length ?? 0) > 0)
|
|
72
|
+
return null;
|
|
73
|
+
if (node.negated === true || node.time === true)
|
|
74
|
+
return null;
|
|
75
|
+
return asSimpleCommand(node.commands[0]);
|
|
76
|
+
}
|
|
77
|
+
function cwdOnlyPath(command) {
|
|
78
|
+
if (command.prefix.length > 0 || command.redirects.length > 0)
|
|
79
|
+
return null;
|
|
80
|
+
if (command.name === undefined || !isLiteralWord(command.name))
|
|
81
|
+
return null;
|
|
82
|
+
let argv0 = command.name.value;
|
|
83
|
+
let suffix = command.suffix;
|
|
84
|
+
if (argv0 === "builtin" || argv0 === "command") {
|
|
85
|
+
const inner = suffix[0];
|
|
86
|
+
if (inner === undefined || !isLiteralWord(inner) || inner.value !== "cd")
|
|
87
|
+
return null;
|
|
88
|
+
argv0 = "cd";
|
|
89
|
+
suffix = suffix.slice(1);
|
|
90
|
+
}
|
|
91
|
+
if (argv0 !== "cd" || suffix.length !== 1)
|
|
92
|
+
return null;
|
|
93
|
+
const dest = suffix[0];
|
|
94
|
+
if (dest === undefined || !isLiteralWord(dest))
|
|
95
|
+
return null;
|
|
96
|
+
const value = dest.value;
|
|
97
|
+
if (value === "" || value === "-" || value === "--" || value.startsWith("-"))
|
|
98
|
+
return null;
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
function isLiteralWord(word) {
|
|
102
|
+
if (word.parts === undefined) {
|
|
103
|
+
return !PARTLESS_FORBIDDEN.test(word.text) && !word.text.startsWith("~");
|
|
104
|
+
}
|
|
105
|
+
return word.parts.every(partIsLiteral);
|
|
106
|
+
}
|
|
107
|
+
function partIsLiteral(part) {
|
|
108
|
+
switch (part.type) {
|
|
109
|
+
case "Literal":
|
|
110
|
+
case "SingleQuoted":
|
|
111
|
+
return true;
|
|
112
|
+
case "AnsiCQuoted":
|
|
113
|
+
return !part.value.includes("\0");
|
|
114
|
+
case "DoubleQuoted":
|
|
115
|
+
return part.parts.every((child) => child.type === "Literal");
|
|
116
|
+
default:
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=peel-cwd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peel-cwd.js","sourceRoot":"","sources":["../src/peel-cwd.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,EAAqD,MAAM,QAAQ,CAAC;AAOlF,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC;IACnC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,C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AC,CAAC;IACvB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACzB,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,IAAU;IAC/B,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,aAAa,CAAC,IAAc;IACnC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,SAAS,CAAC;QACf,KAAK,cAAc;YACjB,OAAO,IAAI,CAAC;QACd,KAAK,aAAa;YAChB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,cAAc;YACjB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC/D;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
package/dist/prep.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Question prep: unbash AST → prepared questions + unparsed acts.
|
|
3
|
+
* Hermetic — no PATH, no process.env, no execution. Word.parts is a lazy
|
|
4
|
+
* getter; this file always reads it. Nested parse errors live on the nested
|
|
5
|
+
* script, not the root.
|
|
6
|
+
*
|
|
7
|
+
* Partition builds I: a known value-flag attaches; an unknown flag followed
|
|
8
|
+
* by a non-dash, non-`--` token forks attached and boolean readings.
|
|
9
|
+
* `valueFlagsFor(argv0, suffix)` sees the leading positional spine — not
|
|
10
|
+
* every descendant under argv0. `=value` and glued shorts stay one reading.
|
|
11
|
+
* `--` never attaches as a value. Cap 16 is open ruling 5; overflow is ⊤I.
|
|
12
|
+
* A nameless command still emits its redirects. `xargs -a FILE` is a read
|
|
13
|
+
* of FILE as well as the inner command.
|
|
14
|
+
*/
|
|
15
|
+
import { type ParseError } from "unbash";
|
|
16
|
+
import { type Which } from "./identity.js";
|
|
17
|
+
import type { Question, Reading } from "./types.js";
|
|
18
|
+
type UnparsedVia = "parse-error" | "control-flow" | "function" | "source" | "test" | "arithmetic" | "coproc" | "find-expression" | "non-literal-argv0" | "script-string";
|
|
19
|
+
type UnparsedAct = {
|
|
20
|
+
readonly via: UnparsedVia;
|
|
21
|
+
readonly source: string;
|
|
22
|
+
};
|
|
23
|
+
type RedirectEmit = {
|
|
24
|
+
readonly operator: string;
|
|
25
|
+
readonly target: string;
|
|
26
|
+
};
|
|
27
|
+
type PreparedQuestion = Question & {
|
|
28
|
+
readonly wrapChain: readonly string[];
|
|
29
|
+
readonly elevated: boolean;
|
|
30
|
+
readonly envDelta: Readonly<Record<string, string>>;
|
|
31
|
+
/** Some argument (or env value) is not fully literal: `$x`, backticks, `$(…)`, brace/bracket/`*`/`?` globs. */
|
|
32
|
+
readonly nonLiteral: boolean;
|
|
33
|
+
readonly redirects: readonly RedirectEmit[];
|
|
34
|
+
readonly background: boolean;
|
|
35
|
+
readonly stdinIsPipe: boolean;
|
|
36
|
+
};
|
|
37
|
+
type PrepResult = {
|
|
38
|
+
readonly questions: readonly PreparedQuestion[];
|
|
39
|
+
readonly unparsed: readonly UnparsedAct[];
|
|
40
|
+
readonly errors: readonly ParseError[];
|
|
41
|
+
/** File effects from commands that have no argv0 (`> .env`). */
|
|
42
|
+
readonly redirects: readonly RedirectEmit[];
|
|
43
|
+
};
|
|
44
|
+
type PrepOpts = {
|
|
45
|
+
readonly valueFlags?: ReadonlySet<string>;
|
|
46
|
+
readonly valueFlagsFor?: (argv0: string, suffix: readonly string[]) => ReadonlySet<string> | undefined;
|
|
47
|
+
/** Path-form peelers are transparent only when this agrees. */
|
|
48
|
+
readonly which?: Which;
|
|
49
|
+
};
|
|
50
|
+
export declare function prep(source: string, opts?: PrepOpts): PrepResult;
|
|
51
|
+
/**
|
|
52
|
+
* Tokenize argv into positionals + flag bag.
|
|
53
|
+
* `closed`: only those names are flags; other dash tokens are positionals.
|
|
54
|
+
* Used when a `"--"` field reopens the suffix — undeclared `-file` stays a path.
|
|
55
|
+
*/
|
|
56
|
+
export declare function partition(words: readonly string[], valueFlags: ReadonlySet<string> | undefined, closed?: ReadonlySet<string>): {
|
|
57
|
+
readings: Reading[];
|
|
58
|
+
overflow: boolean;
|
|
59
|
+
};
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=prep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prep.d.ts","sourceRoot":"","sources":["../src/prep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAML,KAAK,UAAU,EAOhB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,KAAK,WAAW,GACZ,aAAa,GACb,cAAc,GACd,UAAU,GACV,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,QAAQ,GACR,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,CAAC;AAEpB,KAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAA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