@namzu/sdk 44.3.0 → 45.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/CHANGELOG.md +94 -0
- package/dist/authorization/command-line.d.ts +66 -19
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +130 -270
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +7 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +13 -3
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/rules.d.ts +10 -1
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +55 -8
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +152 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -0
- package/dist/authorization/shell-lexer.js +2156 -0
- package/dist/authorization/shell-lexer.js.map +1 -0
- package/dist/authorization/skill-grant.d.ts +182 -0
- package/dist/authorization/skill-grant.d.ts.map +1 -0
- package/dist/authorization/skill-grant.js +314 -0
- package/dist/authorization/skill-grant.js.map +1 -0
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +2 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +1 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/directory/types.d.ts +2 -0
- package/dist/directory/types.d.ts.map +1 -1
- package/dist/directory/types.js.map +1 -1
- package/dist/manager/resident/outbox.d.ts +4 -4
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +5 -2
- package/dist/persona/assembler.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +1 -0
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -1
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +15 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +4 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +12 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +9 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +2 -2
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +6 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/declined.d.ts +12 -0
- package/dist/runtime/query/declined.d.ts.map +1 -0
- package/dist/runtime/query/declined.js +12 -0
- package/dist/runtime/query/declined.js.map +1 -0
- package/dist/runtime/query/executor.d.ts +36 -40
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +95 -53
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +8 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +13 -0
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +13 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/handoff.d.ts +22 -0
- package/dist/runtime/query/iteration/phases/handoff.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/handoff.js +65 -0
- package/dist/runtime/query/iteration/phases/handoff.js.map +1 -0
- package/dist/runtime/query/iteration/phases/index.d.ts +1 -0
- package/dist/runtime/query/iteration/phases/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/index.js +1 -0
- package/dist/runtime/query/iteration/phases/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +56 -3
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +3 -2
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +11 -0
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +36 -3
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +3 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/schedules/cron.d.ts +21 -0
- package/dist/schedules/cron.d.ts.map +1 -0
- package/dist/schedules/cron.js +167 -0
- package/dist/schedules/cron.js.map +1 -0
- package/dist/schedules/describe.d.ts +14 -0
- package/dist/schedules/describe.d.ts.map +1 -0
- package/dist/schedules/describe.js +133 -0
- package/dist/schedules/describe.js.map +1 -0
- package/dist/schedules/errors.d.ts +11 -0
- package/dist/schedules/errors.d.ts.map +1 -0
- package/dist/schedules/errors.js +15 -0
- package/dist/schedules/errors.js.map +1 -0
- package/dist/schedules/evaluate.d.ts +35 -0
- package/dist/schedules/evaluate.d.ts.map +1 -0
- package/dist/schedules/evaluate.js +158 -0
- package/dist/schedules/evaluate.js.map +1 -0
- package/dist/schedules/index.d.ts +11 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +8 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/schedules/next-fire.d.ts +50 -0
- package/dist/schedules/next-fire.d.ts.map +1 -0
- package/dist/schedules/next-fire.js +250 -0
- package/dist/schedules/next-fire.js.map +1 -0
- package/dist/schedules/spec.d.ts +30 -0
- package/dist/schedules/spec.d.ts.map +1 -0
- package/dist/schedules/spec.js +169 -0
- package/dist/schedules/spec.js.map +1 -0
- package/dist/schedules/types.d.ts +144 -0
- package/dist/schedules/types.d.ts.map +1 -0
- package/dist/schedules/types.js +11 -0
- package/dist/schedules/types.js.map +1 -0
- package/dist/schedules/tz.d.ts +44 -0
- package/dist/schedules/tz.d.ts.map +1 -0
- package/dist/schedules/tz.js +141 -0
- package/dist/schedules/tz.js.map +1 -0
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/loader.d.ts +21 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +51 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +18 -6
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser-url.d.ts +83 -0
- package/dist/tools/builtins/browser-url.d.ts.map +1 -0
- package/dist/tools/builtins/browser-url.js +240 -0
- package/dist/tools/builtins/browser-url.js.map +1 -0
- package/dist/tools/builtins/browser.d.ts +367 -0
- package/dist/tools/builtins/browser.d.ts.map +1 -0
- package/dist/tools/builtins/browser.js +704 -0
- package/dist/tools/builtins/browser.js.map +1 -0
- package/dist/tools/builtins/skill.d.ts +2 -9
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +74 -51
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/command-shell.d.ts +90 -0
- package/dist/tools/command-shell.d.ts.map +1 -0
- package/dist/tools/command-shell.js +129 -0
- package/dist/tools/command-shell.js.map +1 -0
- package/dist/tools/defineTool.d.ts +13 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +30 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/schedules/index.d.ts +5 -0
- package/dist/tools/schedules/index.d.ts.map +1 -0
- package/dist/tools/schedules/index.js +4 -0
- package/dist/tools/schedules/index.js.map +1 -0
- package/dist/tools/schedules/loop-tool.d.ts +14 -0
- package/dist/tools/schedules/loop-tool.d.ts.map +1 -0
- package/dist/tools/schedules/loop-tool.js +81 -0
- package/dist/tools/schedules/loop-tool.js.map +1 -0
- package/dist/tools/schedules/present.d.ts +16 -0
- package/dist/tools/schedules/present.d.ts.map +1 -0
- package/dist/tools/schedules/present.js +69 -0
- package/dist/tools/schedules/present.js.map +1 -0
- package/dist/tools/schedules/prompt-scan.d.ts +17 -0
- package/dist/tools/schedules/prompt-scan.d.ts.map +1 -0
- package/dist/tools/schedules/prompt-scan.js +92 -0
- package/dist/tools/schedules/prompt-scan.js.map +1 -0
- package/dist/tools/schedules/schedule-tool.d.ts +16 -0
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -0
- package/dist/tools/schedules/schedule-tool.js +327 -0
- package/dist/tools/schedules/schedule-tool.js.map +1 -0
- package/dist/tools/schedules/types.d.ts +184 -0
- package/dist/tools/schedules/types.d.ts.map +1 -0
- package/dist/tools/schedules/types.js +11 -0
- package/dist/tools/schedules/types.js.map +1 -0
- package/dist/types/authorization/index.d.ts +86 -9
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +11 -1
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/browser/index.d.ts +280 -0
- package/dist/types/browser/index.d.ts.map +1 -0
- package/dist/types/browser/index.js +12 -0
- package/dist/types/browser/index.js.map +1 -0
- package/dist/types/hitl/index.d.ts +23 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/session/events.d.ts +6 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/records.d.ts +23 -0
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +9 -0
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/tool/index.d.ts +108 -5
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +7 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/frontmatter.d.ts +35 -3
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +45 -5
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/id.d.ts +8 -0
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +12 -0
- package/dist/utils/id.js.map +1 -1
- package/package.json +1 -1
- package/src/authorization/command-line.ts +148 -293
- package/src/authorization/gate.ts +22 -2
- package/src/authorization/rules.ts +67 -8
- package/src/authorization/shell-lexer.ts +2349 -0
- package/src/authorization/skill-grant.ts +400 -0
- package/src/bridge/a2a/mapper.ts +2 -0
- package/src/bridge/sse/mapper.ts +1 -0
- package/src/directory/types.ts +2 -0
- package/src/persona/assembler.ts +5 -2
- package/src/prompt/coding-agent-doctrine.ts +1 -0
- package/src/public-runtime.ts +37 -0
- package/src/public-tools.ts +37 -1
- package/src/public-types.ts +57 -0
- package/src/runtime/jobs/registry.ts +19 -11
- package/src/runtime/query/declined.ts +12 -0
- package/src/runtime/query/executor.ts +116 -56
- package/src/runtime/query/index.ts +8 -0
- package/src/runtime/query/iteration/index.ts +13 -0
- package/src/runtime/query/iteration/phases/context.ts +13 -0
- package/src/runtime/query/iteration/phases/handoff.ts +74 -0
- package/src/runtime/query/iteration/phases/index.ts +1 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +55 -3
- package/src/runtime/query/resume-pending.ts +3 -2
- package/src/runtime/query/review-policy.ts +57 -3
- package/src/runtime/query/tooling.ts +4 -0
- package/src/schedules/cron.ts +202 -0
- package/src/schedules/describe.ts +138 -0
- package/src/schedules/errors.ts +15 -0
- package/src/schedules/evaluate.ts +178 -0
- package/src/schedules/index.ts +18 -0
- package/src/schedules/next-fire.ts +257 -0
- package/src/schedules/spec.ts +210 -0
- package/src/schedules/types.ts +163 -0
- package/src/schedules/tz.ts +155 -0
- package/src/skills/index.ts +1 -1
- package/src/skills/loader.ts +59 -1
- package/src/tools/builtins/bash.ts +24 -6
- package/src/tools/builtins/browser-url.ts +251 -0
- package/src/tools/builtins/browser.ts +817 -0
- package/src/tools/builtins/skill.ts +92 -53
- package/src/tools/command-shell.ts +166 -0
- package/src/tools/defineTool.ts +36 -1
- package/src/tools/schedules/index.ts +4 -0
- package/src/tools/schedules/loop-tool.ts +85 -0
- package/src/tools/schedules/present.ts +86 -0
- package/src/tools/schedules/prompt-scan.ts +96 -0
- package/src/tools/schedules/schedule-tool.ts +376 -0
- package/src/tools/schedules/types.ts +197 -0
- package/src/types/authorization/index.ts +60 -2
- package/src/types/browser/index.ts +341 -0
- package/src/types/hitl/index.ts +21 -0
- package/src/types/session/events.ts +6 -0
- package/src/types/session/records.ts +10 -0
- package/src/types/tool/index.ts +109 -5
- package/src/types/tool/presentation.ts +7 -0
- package/src/utils/frontmatter.ts +81 -5
- package/src/utils/id.ts +14 -0
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
* caller must read the two decisions differently, and {@link evaluateRule}
|
|
33
33
|
* does:
|
|
34
34
|
*
|
|
35
|
-
* - **deny** matches when ANY segment matches
|
|
36
|
-
*
|
|
35
|
+
* - **deny** matches when ANY segment matches, or when any command's decoded
|
|
36
|
+
* words ({@link decodedCommands}) do. One prohibited command poisons the
|
|
37
|
+
* line it rides on, however it is quoted.
|
|
37
38
|
* - **allow** matches only when EVERY segment matches, and never when the line
|
|
38
39
|
* is {@link CommandLineDecomposition.opaque}. Permission is a claim about the
|
|
39
40
|
* whole line, and a claim that cannot be checked is not granted.
|
|
@@ -41,307 +42,166 @@
|
|
|
41
42
|
* That asymmetry is the same one `refuse-do-not-degrade` describes: when the
|
|
42
43
|
* analysis is uncertain, the uncertainty spends against the permissive answer.
|
|
43
44
|
*
|
|
45
|
+
* ## Where the commands come from
|
|
46
|
+
*
|
|
47
|
+
* One lexer, {@link lexShellCommandLine}, reads the line the way bash does and
|
|
48
|
+
* is the only thing in the SDK that knows bash's quoting. This module and
|
|
49
|
+
* {@link writesThroughRedirection} are views of its result. There used to be
|
|
50
|
+
* three hand-written walkers here, each with its own idea of where a quote
|
|
51
|
+
* ends, and every disagreement between them was a way to run a command the
|
|
52
|
+
* rules never saw.
|
|
53
|
+
*
|
|
44
54
|
* ## What `opaque` means
|
|
45
55
|
*
|
|
46
56
|
* Some lines contain text that is not the command that runs. Command
|
|
47
57
|
* substitution (`$(…)`, backticks, `<(…)`) executes something whose text is
|
|
48
|
-
* not in the line at all, and `eval` runs a string assembled at
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
58
|
+
* not in the line at all, and `eval` or `source` runs a string assembled at
|
|
59
|
+
* runtime. The lexer also reports a line opaque when it does not parse, or
|
|
60
|
+
* contains a construct it does not model. No decomposition of the source can
|
|
61
|
+
* be a decomposition of what ran, so `allow` declines it. `deny` still tests
|
|
62
|
+
* what is visible, because a deny that matches too much costs a prompt and a
|
|
63
|
+
* deny that matches too little costs the thing it was written to prevent.
|
|
53
64
|
*
|
|
54
65
|
* ## What it deliberately does not do
|
|
55
66
|
*
|
|
56
|
-
* A value
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
67
|
+
* A value that is one plain command comes back as itself, byte for byte. That
|
|
68
|
+
* keeps every rule about a non-command argument — a path, a number, a URL —
|
|
69
|
+
* behaving exactly as it did, and confines this machinery to the case that
|
|
70
|
+
* motivated it.
|
|
60
71
|
*
|
|
61
|
-
* It is a decomposition, not a shell. `xargs sh -c`,
|
|
62
|
-
* file, and a shell invoked through an interpreter it does not
|
|
63
|
-
* pass through as ordinary text. Each of those either denies as
|
|
64
|
-
* an allow rule, fails to match every segment and so declines.
|
|
65
|
-
* is a prompt, never a silent grant.
|
|
72
|
+
* It is a decomposition, not a shell. `xargs sh -c`, `env git push`, a command
|
|
73
|
+
* read from a file, and a shell invoked through an interpreter it does not
|
|
74
|
+
* recognise all pass through as ordinary text. Each of those either denies as
|
|
75
|
+
* before or, for an allow rule, fails to match every segment and so declines.
|
|
76
|
+
* The failure mode is a prompt, never a silent grant.
|
|
66
77
|
*/
|
|
67
|
-
|
|
68
|
-
* Shells whose `-c` argument is another command line.
|
|
69
|
-
*
|
|
70
|
-
* Matched on the basename, so `/bin/bash` and `bash` are the same entry. An
|
|
71
|
-
* interpreter absent from this list is not a hole that grants anything: its
|
|
72
|
-
* payload stays inside one segment, where an allow rule fails to match it.
|
|
73
|
-
*/
|
|
74
|
-
const NESTED_SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'ash', 'busybox']);
|
|
78
|
+
import { basename, lexShellCommandLine, } from './shell-lexer.js';
|
|
75
79
|
/** Commands whose argument is code assembled at runtime. */
|
|
76
80
|
const RUNTIME_EVALUATORS = new Set(['eval', 'source', '.']);
|
|
77
81
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* A line that exceeds either is reported opaque rather than truncated: a
|
|
82
|
+
* Width limit. A line past it is reported opaque rather than truncated: a
|
|
81
83
|
* shortened list of segments would read as complete to `allow`, which is the
|
|
82
84
|
* one reading that must never be wrong.
|
|
83
85
|
*/
|
|
84
|
-
const MAX_DEPTH = 4;
|
|
85
86
|
const MAX_SEGMENTS = 64;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
/**
|
|
88
|
+
* `dialect` is the shell that will run the line (see `ShellDialect`); a
|
|
89
|
+
* caller that does not know passes `sh`, whose reading holds for any POSIX
|
|
90
|
+
* shell.
|
|
91
|
+
*/
|
|
92
|
+
export function decomposeCommandLine(command, dialect = 'bash') {
|
|
93
|
+
const lexed = lex(command, dialect);
|
|
94
|
+
let opaque = lexed.opaque;
|
|
95
|
+
for (const each of lexed.commands) {
|
|
96
|
+
const head = each.words[each.assignments];
|
|
97
|
+
if (head !== undefined && !head.expands && RUNTIME_EVALUATORS.has(basename(head.value))) {
|
|
98
|
+
// The argument is source text assembled elsewhere. Even when it is a
|
|
99
|
+
// visible literal, what runs is decided at runtime.
|
|
100
|
+
opaque = true;
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
|
-
|
|
103
|
+
// A line that does not parse runs none of the text from its error on, and
|
|
104
|
+
// what it ran before that is in `decodedCommands` for deny. The value goes
|
|
105
|
+
// back untouched, the way a path or a URL that is not shell at all does.
|
|
106
|
+
if (!lexed.complete || lexed.commands.length === 0)
|
|
107
|
+
return { segments: [command], opaque };
|
|
108
|
+
// The untouched-value case, kept exact: one command whose text is the
|
|
109
|
+
// whole line. Nothing was cut and nothing was unpacked, so the value goes
|
|
110
|
+
// back as it arrived — which is what keeps a rule about a path or a URL
|
|
111
|
+
// seeing the string it always saw, surrounding space included.
|
|
112
|
+
const only = lexed.commands[0];
|
|
113
|
+
if (lexed.commands.length === 1 &&
|
|
114
|
+
only !== undefined &&
|
|
115
|
+
only.origin === 'line' &&
|
|
116
|
+
only.text === command.trim()) {
|
|
117
|
+
return { segments: [command], opaque };
|
|
118
|
+
}
|
|
119
|
+
const segments = lexed.commands.map((each) => each.text);
|
|
120
|
+
if (segments.length > MAX_SEGMENTS)
|
|
121
|
+
return { segments: segments.slice(0, MAX_SEGMENTS), opaque: true };
|
|
122
|
+
return { segments, opaque };
|
|
101
123
|
}
|
|
102
124
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
125
|
+
* Each command's words as bash passes them (quotes removed, `$'…'` decoded),
|
|
126
|
+
* joined by single spaces — and, for a command led by assignments, the same
|
|
127
|
+
* without them. For `deny` only.
|
|
128
|
+
*
|
|
129
|
+
* A deny rule written as `^git push` must not be evaded by `'git' push`,
|
|
130
|
+
* `g\it push`, `$'git' push` or `GIT_DIR=x git push`: the source text of each
|
|
131
|
+
* differs from the pattern and the command that runs does not. `allow` does
|
|
132
|
+
* not use these. Its subject stays the source text, so a pattern that names
|
|
133
|
+
* quotes keeps meaning what its author wrote, and a decoded form can only ever
|
|
134
|
+
* add a match — which for `deny` is the safe direction and for `allow` is not.
|
|
109
135
|
*/
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const cut = () => {
|
|
115
|
-
const trimmed = trimSegment(current);
|
|
116
|
-
current = '';
|
|
117
|
-
if (trimmed === '')
|
|
118
|
-
return;
|
|
119
|
-
for (const piece of expand(trimmed, state, depth))
|
|
120
|
-
segments.push(piece);
|
|
121
|
-
};
|
|
122
|
-
for (let i = 0; i < command.length; i += 1) {
|
|
123
|
-
const char = command[i];
|
|
124
|
-
if (quote === "'") {
|
|
125
|
-
// Single quotes suspend everything, including the backslash. This is
|
|
126
|
-
// the branch that keeps `echo 'a && b'` one command.
|
|
127
|
-
if (char === "'")
|
|
128
|
-
quote = null;
|
|
129
|
-
current += char;
|
|
136
|
+
export function decodedCommands(command, dialect = 'bash') {
|
|
137
|
+
const out = [];
|
|
138
|
+
for (const each of lex(command, dialect).commands) {
|
|
139
|
+
if (each.words.length === 0)
|
|
130
140
|
continue;
|
|
141
|
+
out.push(each.words.map((word) => word.value).join(' '));
|
|
142
|
+
if (each.assignments > 0 && each.words.length > each.assignments) {
|
|
143
|
+
out.push(each.words
|
|
144
|
+
.slice(each.assignments)
|
|
145
|
+
.map((word) => word.value)
|
|
146
|
+
.join(' '));
|
|
131
147
|
}
|
|
132
|
-
if (char === '\\') {
|
|
133
|
-
// An escaped separator is a literal, so both characters go through
|
|
134
|
-
// untouched and the next loop never sees the separator as one.
|
|
135
|
-
current += char + (command[i + 1] ?? '');
|
|
136
|
-
i += 1;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (quote === '"') {
|
|
140
|
-
if (char === '"')
|
|
141
|
-
quote = null;
|
|
142
|
-
// Substitution is live inside double quotes, which is exactly where
|
|
143
|
-
// it hides best.
|
|
144
|
-
else if (isSubstitutionStart(command, i))
|
|
145
|
-
state.opaque = true;
|
|
146
|
-
current += char;
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
if (char === "'" || char === '"') {
|
|
150
|
-
quote = char;
|
|
151
|
-
current += char;
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (isSubstitutionStart(command, i)) {
|
|
155
|
-
state.opaque = true;
|
|
156
|
-
current += char;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
const separator = separatorAt(command, i);
|
|
160
|
-
if (separator > 0) {
|
|
161
|
-
state.structured = true;
|
|
162
|
-
cut();
|
|
163
|
-
i += separator - 1;
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
current += char;
|
|
167
148
|
}
|
|
168
|
-
|
|
169
|
-
// not what this walk saw, so the caller must not treat the result as a
|
|
170
|
-
// complete account.
|
|
171
|
-
if (quote !== null)
|
|
172
|
-
state.opaque = true;
|
|
173
|
-
cut();
|
|
174
|
-
return segments;
|
|
149
|
+
return out;
|
|
175
150
|
}
|
|
176
151
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
152
|
+
* Whether a command line sends output into a file through a shell redirection.
|
|
153
|
+
*
|
|
154
|
+
* A permission pattern names commands. `>`, `>>`, `>|`, `&>`, `&>>`, `<>` and
|
|
155
|
+
* `>&word` open a file for writing whose path is not the command's argument,
|
|
156
|
+
* so a pattern that covers `git status *` would otherwise also cover
|
|
157
|
+
* `git status > ~/.bashrc`. Callers that grant on a pattern's say-so decline
|
|
158
|
+
* such a line.
|
|
159
|
+
*
|
|
160
|
+
* Not writes: a target of `/dev/null`, descriptor duplication and closing
|
|
161
|
+
* (`2>&1`, `>&2`, `>&-`), and anything quoted or escaped so that it is not an
|
|
162
|
+
* operator. Anything whose target is not known before the line runs — a
|
|
163
|
+
* target built from a variable, a glob or a tilde — counts as a write, and so
|
|
164
|
+
* does a line that does not parse or holds a process substitution: the
|
|
165
|
+
* uncertainty spends against the grant.
|
|
183
166
|
*/
|
|
184
|
-
function
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
if (char === '\n')
|
|
188
|
-
return 1;
|
|
189
|
-
if (char === ';')
|
|
190
|
-
return next === ';' ? 2 : 1;
|
|
191
|
-
if (char === '&') {
|
|
192
|
-
if (next === '&')
|
|
193
|
-
return 2;
|
|
194
|
-
if (next === '>')
|
|
195
|
-
return 0;
|
|
196
|
-
if (command[index - 1] === '>')
|
|
197
|
-
return 0;
|
|
198
|
-
return 1;
|
|
199
|
-
}
|
|
200
|
-
if (char === '|') {
|
|
201
|
-
if (next === '|')
|
|
202
|
-
return 2;
|
|
203
|
-
// `|&` pipes stderr as well; still a pipe, and both sides still run.
|
|
204
|
-
if (next === '&')
|
|
205
|
-
return 2;
|
|
206
|
-
return 1;
|
|
207
|
-
}
|
|
208
|
-
return 0;
|
|
209
|
-
}
|
|
210
|
-
/** Whether a command substitution opens here. */
|
|
211
|
-
function isSubstitutionStart(command, index) {
|
|
212
|
-
const char = command[index];
|
|
213
|
-
if (char === '`')
|
|
167
|
+
export function writesThroughRedirection(command, dialect = 'bash') {
|
|
168
|
+
const lexed = lex(command, dialect);
|
|
169
|
+
if (!lexed.complete)
|
|
214
170
|
return true;
|
|
215
|
-
if (
|
|
171
|
+
if (lexed.reasons.includes('process substitution'))
|
|
216
172
|
return true;
|
|
217
|
-
|
|
218
|
-
if ((char === '<' || char === '>') && command[index + 1] === '(')
|
|
219
|
-
return true;
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Strip the grouping punctuation a split leaves behind.
|
|
224
|
-
*
|
|
225
|
-
* `(cd build && make)` cuts into `(cd build` and `make)`. Leaving the bracket on
|
|
226
|
-
* would stop an allow rule matching a command it names, and — worse — stop a
|
|
227
|
-
* deny rule matching one, since `^make` does not match `make)`.
|
|
228
|
-
*/
|
|
229
|
-
function trimSegment(segment) {
|
|
230
|
-
return segment
|
|
231
|
-
.trim()
|
|
232
|
-
.replace(/^[({\s]+/, '')
|
|
233
|
-
.replace(/[)}\s]+$/, '');
|
|
173
|
+
return lexed.redirections.some(writes);
|
|
234
174
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (RUNTIME_EVALUATORS.has(basename(head.text))) {
|
|
253
|
-
// The argument is source text assembled elsewhere. Even when it is a
|
|
254
|
-
// visible literal, what runs is decided at runtime.
|
|
255
|
-
state.opaque = true;
|
|
256
|
-
return [segment];
|
|
257
|
-
}
|
|
258
|
-
if (!NESTED_SHELLS.has(basename(head.text)))
|
|
259
|
-
return [segment];
|
|
260
|
-
const flag = words.findIndex((word, index) => index > 0 && word.quoted === null && word.text === '-c');
|
|
261
|
-
if (flag < 0)
|
|
262
|
-
return [segment];
|
|
263
|
-
const payload = words[flag + 1];
|
|
264
|
-
if (payload === undefined) {
|
|
265
|
-
// `bash -c` with nothing after it is either a syntax error or an
|
|
266
|
-
// argument this tokenizer failed to read. Neither may be reported as
|
|
267
|
-
// "there is no nested command".
|
|
268
|
-
state.opaque = true;
|
|
269
|
-
return [segment];
|
|
270
|
-
}
|
|
271
|
-
if (depth + 1 >= MAX_DEPTH) {
|
|
272
|
-
state.opaque = true;
|
|
273
|
-
return [segment];
|
|
175
|
+
function writes(redirection) {
|
|
176
|
+
const { operator, target } = redirection;
|
|
177
|
+
switch (operator) {
|
|
178
|
+
case '<':
|
|
179
|
+
case '<&':
|
|
180
|
+
case '<<':
|
|
181
|
+
case '<<-':
|
|
182
|
+
case '<<<':
|
|
183
|
+
return false;
|
|
184
|
+
case '>&':
|
|
185
|
+
// `>&N`, `>&N-`, `>&-` duplicate or close a descriptor. `>&word`
|
|
186
|
+
// with any other word redirects both streams into that file.
|
|
187
|
+
if (!target.expands && /^(?:\d+-?|-)$/.test(target.value))
|
|
188
|
+
return false;
|
|
189
|
+
return target.expands || target.value !== '/dev/null';
|
|
190
|
+
default:
|
|
191
|
+
return target.expands || target.value !== '/dev/null';
|
|
274
192
|
}
|
|
275
|
-
const nested = split(payload.text, state, depth + 1);
|
|
276
|
-
if (nested.length === 0)
|
|
277
|
-
return [segment];
|
|
278
|
-
state.structured = true;
|
|
279
|
-
return [segment, ...nested];
|
|
280
193
|
}
|
|
281
194
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* The quote is reported rather than discarded because `-c` must be the flag and
|
|
285
|
-
* not a literal: `echo "-c"` names no nested shell, and treating its next word
|
|
286
|
-
* as a command line would decompose a string that never runs.
|
|
195
|
+
* One gate evaluation tests the same line against every rule, and each rule
|
|
196
|
+
* asks for it again. The last line lexed is kept so that is one lexing.
|
|
287
197
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
let sawQuote = null;
|
|
293
|
-
let open = false;
|
|
294
|
-
const push = () => {
|
|
295
|
-
if (open)
|
|
296
|
-
words.push({ text: current, quoted: sawQuote });
|
|
297
|
-
current = '';
|
|
298
|
-
sawQuote = null;
|
|
299
|
-
open = false;
|
|
300
|
-
};
|
|
301
|
-
for (let i = 0; i < segment.length; i += 1) {
|
|
302
|
-
const char = segment[i];
|
|
303
|
-
if (quote === "'") {
|
|
304
|
-
// Single quotes suspend the backslash too, so this branch precedes
|
|
305
|
-
// the escape below rather than sharing it.
|
|
306
|
-
if (char === "'")
|
|
307
|
-
quote = null;
|
|
308
|
-
else
|
|
309
|
-
current += char;
|
|
310
|
-
open = true;
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (char === '\\' && i + 1 < segment.length) {
|
|
314
|
-
current += segment[i + 1];
|
|
315
|
-
i += 1;
|
|
316
|
-
open = true;
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
if (quote === '"') {
|
|
320
|
-
if (char === '"')
|
|
321
|
-
quote = null;
|
|
322
|
-
else
|
|
323
|
-
current += char;
|
|
324
|
-
open = true;
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
if (char === "'" || char === '"') {
|
|
328
|
-
quote = char;
|
|
329
|
-
sawQuote = char;
|
|
330
|
-
open = true;
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
if (char === ' ' || char === '\t') {
|
|
334
|
-
push();
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
current += char;
|
|
338
|
-
open = true;
|
|
198
|
+
let cached;
|
|
199
|
+
function lex(command, dialect) {
|
|
200
|
+
if (cached !== undefined && cached.command === command && cached.dialect === dialect) {
|
|
201
|
+
return cached.result;
|
|
339
202
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
function basename(word) {
|
|
344
|
-
const cut = word.lastIndexOf('/');
|
|
345
|
-
return cut < 0 ? word : word.slice(cut + 1);
|
|
203
|
+
const result = lexShellCommandLine(command, { dialect });
|
|
204
|
+
cached = { command, dialect, result };
|
|
205
|
+
return result;
|
|
346
206
|
}
|
|
347
207
|
//# sourceMappingURL=command-line.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-line.js","sourceRoot":"","sources":["../../src/authorization/command-line.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"command-line.js","sourceRoot":"","sources":["../../src/authorization/command-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAIN,QAAQ,EACR,mBAAmB,GACnB,MAAM,kBAAkB,CAAA;AAgBzB,4DAA4D;AAC5D,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AAmB,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IACxD,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;IACrC,OAAO,MAAM,CAAA;AACd,CAAC"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { AuthorizationGateConfig, AuthorizationRule, GateEvaluationResult } from '../types/authorization/index.js';
|
|
2
2
|
import type { ToolDefinition } from '../types/tool/index.js';
|
|
3
3
|
import type { Logger } from '../utils/logger.js';
|
|
4
|
+
import type { ShellDialect } from './shell-lexer.js';
|
|
4
5
|
export interface ToolCallContext {
|
|
5
6
|
readonly toolName: string;
|
|
6
7
|
readonly toolInput: unknown;
|
|
7
8
|
readonly toolDef: ToolDefinition | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The shell this call's command line will run in, when the caller knows
|
|
11
|
+
* (`ToolDefinition.commandDialect`). Absent, a command line is read in the
|
|
12
|
+
* `sh` dialect, which holds whichever shell runs it.
|
|
13
|
+
*/
|
|
14
|
+
readonly commandDialect?: ShellDialect;
|
|
8
15
|
}
|
|
9
16
|
/**
|
|
10
17
|
* What the rule actually said, in words a model can act on.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/authorization/gate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,iCAAiC,CAAA;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/authorization/gate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,iCAAiC,CAAA;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,CAAA;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,YAAY,CAAA;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CA4C5D;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,uBAAuB,EAAE,GAAG,EAAE,MAAM;IAiHxD,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,oBAAoB;CAyDpD"}
|
|
@@ -36,14 +36,24 @@ export function describeRule(rule) {
|
|
|
36
36
|
// Names the argument, not just the pattern. That is what tells a
|
|
37
37
|
// model whether a different value could get through — which is the
|
|
38
38
|
// difference between rewording once and rewording forever.
|
|
39
|
-
const verb = rule.decision === 'deny'
|
|
39
|
+
const verb = rule.decision === 'deny'
|
|
40
|
+
? 'denied'
|
|
41
|
+
: rule.decision === 'review'
|
|
42
|
+
? 'sent for review'
|
|
43
|
+
: 'allowed';
|
|
40
44
|
return `${verb} because the \`${rule.argument}\` argument matched ${rule.pattern} (this rule applies to ${rule.toolNames.join(', ')})`;
|
|
41
45
|
}
|
|
42
46
|
case 'custom_pattern': {
|
|
43
47
|
const where = rule.target === 'both' ? 'name or arguments' : rule.target;
|
|
44
|
-
const verb = rule.decision === 'deny'
|
|
48
|
+
const verb = rule.decision === 'deny'
|
|
49
|
+
? 'denied'
|
|
50
|
+
: rule.decision === 'review'
|
|
51
|
+
? 'sent for review'
|
|
52
|
+
: 'allowed';
|
|
45
53
|
return `${verb} by a pattern rule matching the ${where}: ${rule.pattern}`;
|
|
46
54
|
}
|
|
55
|
+
case 'predicate':
|
|
56
|
+
return rule.description;
|
|
47
57
|
default: {
|
|
48
58
|
const exhaustive = rule;
|
|
49
59
|
return `matched an unrecognised rule: ${JSON.stringify(exhaustive)}`;
|
|
@@ -175,7 +185,7 @@ export class AuthorizationGate {
|
|
|
175
185
|
const rule = this.rules[i];
|
|
176
186
|
if (!rule)
|
|
177
187
|
continue;
|
|
178
|
-
const decision = evaluateRule(rule, ctx.toolName, ctx.toolInput, ctx.toolDef, this.compiledPatterns.get(i), this.nameSets.get(i));
|
|
188
|
+
const decision = evaluateRule(rule, ctx.toolName, ctx.toolInput, ctx.toolDef, this.compiledPatterns.get(i), this.nameSets.get(i), ctx.commandDialect !== undefined ? { commandDialect: ctx.commandDialect } : {});
|
|
179
189
|
if (decision !== null) {
|
|
180
190
|
const result = {
|
|
181
191
|
decision,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../../src/authorization/gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AAMvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
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,CAAC,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE;gBACzC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,QAAQ;gBAC/B,8BAA8B,EAAE,QAAQ;aACxC,CAAC,CAAA;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACd,CAAC;CACD"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { AuthorizationRule, GateDecision } from '../types/authorization/index.js';
|
|
2
2
|
import type { ToolDefinition } from '../types/tool/index.js';
|
|
3
|
-
|
|
3
|
+
import type { ShellDialect } from './shell-lexer.js';
|
|
4
|
+
export interface EvaluateRuleOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The shell the tool will run a command-line argument in. Default `sh`:
|
|
7
|
+
* every construct bash and a POSIX shell read differently makes the line
|
|
8
|
+
* opaque. `ToolDefinition.commandDialect` supplies it for a tool.
|
|
9
|
+
*/
|
|
10
|
+
readonly commandDialect?: ShellDialect;
|
|
11
|
+
}
|
|
12
|
+
export declare function evaluateRule(rule: AuthorizationRule, toolName: string, toolInput: unknown, toolDef: ToolDefinition | undefined, compiledPattern?: RegExp, nameSet?: Set<string>, options?: EvaluateRuleOptions): GateDecision | null;
|
|
4
13
|
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/authorization/rules.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/authorization/rules.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,WAAW,mBAAmB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,YAAY,CAAA;CACtC;AAED,wBAAgB,YAAY,CAC3B,IAAI,EAAE,iBAAiB,EACvB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,eAAe,CAAC,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EACrB,OAAO,GAAE,mBAAwB,GAC/B,YAAY,GAAG,IAAI,CAkLrB"}
|