@namzu/sdk 69.2.0 → 69.4.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.
Files changed (160) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  3. package/dist/authorization/readonly-commands.js +30 -2
  4. package/dist/authorization/readonly-commands.js.map +1 -1
  5. package/dist/constants/plugin/index.d.ts +8 -0
  6. package/dist/constants/plugin/index.d.ts.map +1 -1
  7. package/dist/constants/plugin/index.js +8 -0
  8. package/dist/constants/plugin/index.js.map +1 -1
  9. package/dist/plugin/common-layout/index.d.ts +5 -0
  10. package/dist/plugin/common-layout/index.d.ts.map +1 -0
  11. package/dist/plugin/common-layout/index.js +3 -0
  12. package/dist/plugin/common-layout/index.js.map +1 -0
  13. package/dist/plugin/common-layout/mcp.d.ts +21 -0
  14. package/dist/plugin/common-layout/mcp.d.ts.map +1 -0
  15. package/dist/plugin/common-layout/mcp.js +305 -0
  16. package/dist/plugin/common-layout/mcp.js.map +1 -0
  17. package/dist/plugin/common-layout/paths.d.ts +27 -0
  18. package/dist/plugin/common-layout/paths.d.ts.map +1 -0
  19. package/dist/plugin/common-layout/paths.js +48 -0
  20. package/dist/plugin/common-layout/paths.js.map +1 -0
  21. package/dist/plugin/common-layout/read.d.ts +25 -0
  22. package/dist/plugin/common-layout/read.d.ts.map +1 -0
  23. package/dist/plugin/common-layout/read.js +1155 -0
  24. package/dist/plugin/common-layout/read.js.map +1 -0
  25. package/dist/plugin/common-layout/types.d.ts +66 -0
  26. package/dist/plugin/common-layout/types.d.ts.map +1 -0
  27. package/dist/plugin/common-layout/types.js +2 -0
  28. package/dist/plugin/common-layout/types.js.map +1 -0
  29. package/dist/plugin/common-layout-names.d.ts +65 -0
  30. package/dist/plugin/common-layout-names.d.ts.map +1 -0
  31. package/dist/plugin/common-layout-names.js +94 -0
  32. package/dist/plugin/common-layout-names.js.map +1 -0
  33. package/dist/plugin/hook-module/capabilities.d.ts +41 -0
  34. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -0
  35. package/dist/plugin/hook-module/capabilities.js +438 -0
  36. package/dist/plugin/hook-module/capabilities.js.map +1 -0
  37. package/dist/plugin/hook-module/consent.d.ts +39 -0
  38. package/dist/plugin/hook-module/consent.d.ts.map +1 -0
  39. package/dist/plugin/hook-module/consent.js +59 -0
  40. package/dist/plugin/hook-module/consent.js.map +1 -0
  41. package/dist/plugin/hook-module/events.d.ts +33 -0
  42. package/dist/plugin/hook-module/events.d.ts.map +1 -0
  43. package/dist/plugin/hook-module/events.js +149 -0
  44. package/dist/plugin/hook-module/events.js.map +1 -0
  45. package/dist/plugin/hook-module/host.d.ts +79 -0
  46. package/dist/plugin/hook-module/host.d.ts.map +1 -0
  47. package/dist/plugin/hook-module/host.js +546 -0
  48. package/dist/plugin/hook-module/host.js.map +1 -0
  49. package/dist/plugin/hook-module/index.d.ts +11 -0
  50. package/dist/plugin/hook-module/index.d.ts.map +1 -0
  51. package/dist/plugin/hook-module/index.js +6 -0
  52. package/dist/plugin/hook-module/index.js.map +1 -0
  53. package/dist/plugin/hook-module/scan.d.ts +99 -0
  54. package/dist/plugin/hook-module/scan.d.ts.map +1 -0
  55. package/dist/plugin/hook-module/scan.js +789 -0
  56. package/dist/plugin/hook-module/scan.js.map +1 -0
  57. package/dist/plugin/hook-module/worker-source.d.ts +31 -0
  58. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -0
  59. package/dist/plugin/hook-module/worker-source.js +498 -0
  60. package/dist/plugin/hook-module/worker-source.js.map +1 -0
  61. package/dist/plugin/index.d.ts +5 -2
  62. package/dist/plugin/index.d.ts.map +1 -1
  63. package/dist/plugin/index.js +4 -1
  64. package/dist/plugin/index.js.map +1 -1
  65. package/dist/plugin/lifecycle.d.ts +57 -0
  66. package/dist/plugin/lifecycle.d.ts.map +1 -1
  67. package/dist/plugin/lifecycle.js +92 -11
  68. package/dist/plugin/lifecycle.js.map +1 -1
  69. package/dist/plugin/loader.d.ts +30 -0
  70. package/dist/plugin/loader.d.ts.map +1 -1
  71. package/dist/plugin/loader.js +76 -19
  72. package/dist/plugin/loader.js.map +1 -1
  73. package/dist/plugin/shell-hook-env.d.ts +7 -0
  74. package/dist/plugin/shell-hook-env.d.ts.map +1 -1
  75. package/dist/plugin/shell-hook-env.js.map +1 -1
  76. package/dist/plugin/shell-hook.d.ts +10 -1
  77. package/dist/plugin/shell-hook.d.ts.map +1 -1
  78. package/dist/plugin/shell-hook.js +81 -70
  79. package/dist/plugin/shell-hook.js.map +1 -1
  80. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  81. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  82. package/dist/prompt/coding-agent-doctrine.js +1 -1
  83. package/dist/provider/side-request-reasoning.d.ts.map +1 -1
  84. package/dist/provider/side-request-reasoning.js +5 -1
  85. package/dist/provider/side-request-reasoning.js.map +1 -1
  86. package/dist/public-runtime.d.ts +3 -2
  87. package/dist/public-runtime.d.ts.map +1 -1
  88. package/dist/public-runtime.js +2 -2
  89. package/dist/public-runtime.js.map +1 -1
  90. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  91. package/dist/runtime/query/auto-review/classifier.js +13 -2
  92. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  93. package/dist/runtime/query/auto-review/failure.d.ts +12 -5
  94. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -1
  95. package/dist/runtime/query/auto-review/failure.js +42 -7
  96. package/dist/runtime/query/auto-review/failure.js.map +1 -1
  97. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  98. package/dist/runtime/query/review-policy.js +22 -6
  99. package/dist/runtime/query/review-policy.js.map +1 -1
  100. package/dist/runtime/query/turn/check-scope.d.ts +18 -0
  101. package/dist/runtime/query/turn/check-scope.d.ts.map +1 -0
  102. package/dist/runtime/query/turn/check-scope.js +90 -0
  103. package/dist/runtime/query/turn/check-scope.js.map +1 -0
  104. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  105. package/dist/runtime/query/turn/outcome-ledger.js +13 -0
  106. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  107. package/dist/skills/loader.d.ts +8 -2
  108. package/dist/skills/loader.d.ts.map +1 -1
  109. package/dist/skills/loader.js +22 -11
  110. package/dist/skills/loader.js.map +1 -1
  111. package/dist/skills/registry.d.ts.map +1 -1
  112. package/dist/skills/registry.js +9 -1
  113. package/dist/skills/registry.js.map +1 -1
  114. package/dist/tools/builtins/job.d.ts.map +1 -1
  115. package/dist/tools/builtins/job.js +4 -1
  116. package/dist/tools/builtins/job.js.map +1 -1
  117. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  118. package/dist/tools/builtins/wait-for-job.js +2 -1
  119. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  120. package/dist/types/plugin/index.d.ts +73 -0
  121. package/dist/types/plugin/index.d.ts.map +1 -1
  122. package/dist/types/plugin/index.js +28 -6
  123. package/dist/types/plugin/index.js.map +1 -1
  124. package/dist/types/skills/index.d.ts +6 -0
  125. package/dist/types/skills/index.d.ts.map +1 -1
  126. package/package.json +2 -1
  127. package/src/authorization/readonly-commands.ts +30 -2
  128. package/src/constants/plugin/index.ts +9 -0
  129. package/src/plugin/common-layout/index.ts +19 -0
  130. package/src/plugin/common-layout/mcp.ts +362 -0
  131. package/src/plugin/common-layout/paths.ts +70 -0
  132. package/src/plugin/common-layout/read.ts +1282 -0
  133. package/src/plugin/common-layout/types.ts +77 -0
  134. package/src/plugin/common-layout-names.ts +108 -0
  135. package/src/plugin/hook-module/capabilities.ts +500 -0
  136. package/src/plugin/hook-module/consent.ts +96 -0
  137. package/src/plugin/hook-module/events.ts +177 -0
  138. package/src/plugin/hook-module/host.ts +649 -0
  139. package/src/plugin/hook-module/index.ts +52 -0
  140. package/src/plugin/hook-module/scan.ts +1004 -0
  141. package/src/plugin/hook-module/worker-source.ts +500 -0
  142. package/src/plugin/index.ts +13 -1
  143. package/src/plugin/lifecycle.ts +179 -17
  144. package/src/plugin/loader.ts +97 -18
  145. package/src/plugin/shell-hook-env.ts +7 -0
  146. package/src/plugin/shell-hook.ts +91 -70
  147. package/src/prompt/coding-agent-doctrine.ts +1 -1
  148. package/src/provider/side-request-reasoning.ts +5 -1
  149. package/src/public-runtime.ts +35 -0
  150. package/src/runtime/query/auto-review/classifier.ts +14 -2
  151. package/src/runtime/query/auto-review/failure.ts +52 -7
  152. package/src/runtime/query/review-policy.ts +30 -6
  153. package/src/runtime/query/turn/check-scope.ts +90 -0
  154. package/src/runtime/query/turn/outcome-ledger.ts +11 -0
  155. package/src/skills/loader.ts +26 -9
  156. package/src/skills/registry.ts +9 -1
  157. package/src/tools/builtins/job.ts +4 -1
  158. package/src/tools/builtins/wait-for-job.ts +3 -1
  159. package/src/types/plugin/index.ts +81 -24
  160. package/src/types/skills/index.ts +7 -0
@@ -0,0 +1,149 @@
1
+ import { COMMON_MODULE_EVENT_NAMESPACE } from '../common-layout-names.js';
2
+ import { SHELL_HOOK_EVENTS, SHELL_HOOK_PASCAL_EVENT_NAMES, } from '../shell-hook.js';
3
+ /**
4
+ * The settings-style hook events a hooks module may name, as `classic.<Event>`.
5
+ * Some have no counterpart in Namzu; they are accepted and never run.
6
+ */
7
+ export const CLASSIC_HOOK_EVENTS = [
8
+ 'PreToolUse',
9
+ 'PostToolUse',
10
+ 'PostToolUseFailure',
11
+ 'PostToolBatch',
12
+ 'PermissionDenied',
13
+ 'Notification',
14
+ 'UserPromptSubmit',
15
+ 'UserPromptExpansion',
16
+ 'SessionStart',
17
+ 'SessionEnd',
18
+ 'Stop',
19
+ 'StopFailure',
20
+ 'SubagentStart',
21
+ 'SubagentStop',
22
+ 'PreCompact',
23
+ 'PostCompact',
24
+ 'PreModelSwitch',
25
+ 'PostModelSwitch',
26
+ 'PermissionRequest',
27
+ 'Setup',
28
+ 'TeammateIdle',
29
+ 'TaskCreated',
30
+ 'TaskCompleted',
31
+ 'Elicitation',
32
+ 'ElicitationResult',
33
+ 'ConfigChange',
34
+ 'InstructionsLoaded',
35
+ 'WorktreeCreate',
36
+ 'WorktreeRemove',
37
+ 'CwdChanged',
38
+ 'FileChanged',
39
+ 'DirectoryAdded',
40
+ 'MessageDisplay',
41
+ 'PreSkillShellCommand',
42
+ ];
43
+ /**
44
+ * The namespaces of the events the other engine runs inside itself (tool calls,
45
+ * the interface, agents and the rest). A module may register on them; Namzu has
46
+ * no such events, so none of those hooks run.
47
+ */
48
+ const ENGINE_NAMESPACES = new Set([
49
+ 'tool',
50
+ 'turn',
51
+ 'session',
52
+ 'prompt',
53
+ 'agent',
54
+ 'command',
55
+ 'config',
56
+ 'settings',
57
+ 'env',
58
+ 'state',
59
+ 'store',
60
+ 'telemetry',
61
+ 'skill',
62
+ 'attribution',
63
+ 'ui',
64
+ 'theme',
65
+ 'vcs',
66
+ 'process',
67
+ 'fs',
68
+ 'http',
69
+ 'model',
70
+ 'mcp',
71
+ 'audio',
72
+ 'clock',
73
+ 'wasm',
74
+ 'plugin',
75
+ 'engine',
76
+ ]);
77
+ const NAMESPACE = COMMON_MODULE_EVENT_NAMESPACE;
78
+ /** Each classic name that Namzu has an event for, to that event. */
79
+ const CLASSIC_TO_NAMZU = new Map(SHELL_HOOK_EVENTS.flatMap((event) => {
80
+ const written = SHELL_HOOK_PASCAL_EVENT_NAMES[event];
81
+ return written !== undefined && CLASSIC_HOOK_EVENTS.includes(written)
82
+ ? [[written, event]]
83
+ : [];
84
+ }));
85
+ const NAMZU_TO_CLASSIC = new Map([...CLASSIC_TO_NAMZU].map(([classic, event]) => [event, classic]));
86
+ /** The Namzu events a module can run on. */
87
+ export const MODULE_HOOK_EVENTS = [...NAMZU_TO_CLASSIC.keys()];
88
+ /** The name a module registers on for a Namzu event: `classic.PreToolUse`. */
89
+ export function classicEventName(event) {
90
+ const written = NAMZU_TO_CLASSIC.get(event);
91
+ return written === undefined ? undefined : `${NAMESPACE}.${written}`;
92
+ }
93
+ /** The written (PascalCase) name of a Namzu event, as a module's `e.hook_event_name` spells it. */
94
+ export function classicWrittenName(event) {
95
+ return NAMZU_TO_CLASSIC.get(event);
96
+ }
97
+ function notAvailable(pattern) {
98
+ return `Namzu runs ${NAMESPACE}.* hooks from modules; ${pattern} is not available.`;
99
+ }
100
+ function isEngineName(name) {
101
+ const dot = name.indexOf('.');
102
+ if (dot <= 0 || dot === name.length - 1)
103
+ return false;
104
+ return (ENGINE_NAMESPACES.has(name.slice(0, dot)) && /^[A-Za-z][A-Za-z0-9]*$/.test(name.slice(dot + 1)));
105
+ }
106
+ /**
107
+ * What a pattern selects: one event by name, every event under a namespace
108
+ * (`classic.*`), every event (`*`), or every event but those another pattern
109
+ * selects (`!tool.*`, `!classic.Stop`). A name that is no event and a glob that
110
+ * selects nothing are refused.
111
+ */
112
+ export function resolvePattern(pattern) {
113
+ const all = () => [...MODULE_HOOK_EVENTS];
114
+ if (pattern === '*')
115
+ return { ok: true, runs: all() };
116
+ if (pattern.startsWith('!')) {
117
+ const inner = resolvePattern(pattern.slice(1));
118
+ if (!inner.ok)
119
+ return inner;
120
+ if (pattern.startsWith('!!')) {
121
+ return { ok: false, message: `"${pattern}" is not a pattern: a negation is made once` };
122
+ }
123
+ const taken = new Set(inner.runs);
124
+ return { ok: true, runs: all().filter((event) => !taken.has(event)) };
125
+ }
126
+ if (pattern.endsWith('.*')) {
127
+ const space = pattern.slice(0, -2);
128
+ if (space === NAMESPACE)
129
+ return { ok: true, runs: all() };
130
+ if (ENGINE_NAMESPACES.has(space)) {
131
+ return { ok: true, runs: [], notUsed: notAvailable(pattern) };
132
+ }
133
+ return { ok: false, message: `"${pattern}" is not a pattern: it selects no event` };
134
+ }
135
+ if (pattern.startsWith(`${NAMESPACE}.`)) {
136
+ const name = pattern.slice(NAMESPACE.length + 1);
137
+ if (!CLASSIC_HOOK_EVENTS.includes(name)) {
138
+ return { ok: false, message: `"${pattern}" is not an event` };
139
+ }
140
+ const event = CLASSIC_TO_NAMZU.get(name);
141
+ return event === undefined
142
+ ? { ok: true, runs: [], notUsed: notAvailable(pattern) }
143
+ : { ok: true, runs: [event] };
144
+ }
145
+ if (isEngineName(pattern))
146
+ return { ok: true, runs: [], notUsed: notAvailable(pattern) };
147
+ return { ok: false, message: `"${pattern}" is not an event` };
148
+ }
149
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/plugin/hook-module/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,EACN,iBAAiB,EACjB,6BAA6B,GAE7B,MAAM,kBAAkB,CAAA;AAEzB;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACrD,YAAY;IACZ,aAAa;IACb,oBAAoB;IACpB,eAAe;IACf,kBAAkB;IAClB,cAAc;IACd,kBAAkB;IAClB,qBAAqB;IACrB,cAAc;IACd,YAAY;IACZ,MAAM;IACN,aAAa;IACb,eAAe;IACf,cAAc;IACd,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,iBAAiB;IACjB,mBAAmB;IACnB,OAAO;IACP,cAAc;IACd,aAAa;IACb,eAAe;IACf,aAAa;IACb,mBAAmB;IACnB,cAAc;IACd,oBAAoB;IACpB,gBAAgB;IAChB,gBAAgB;IAChB,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,gBAAgB;IAChB,sBAAsB;CACtB,CAAA;AAED;;;;GAIG;AACH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACtD,MAAM;IACN,MAAM;IACN,SAAS;IACT,QAAQ;IACR,OAAO;IACP,SAAS;IACT,QAAQ;IACR,UAAU;IACV,KAAK;IACL,OAAO;IACP,OAAO;IACP,WAAW;IACX,OAAO;IACP,aAAa;IACb,IAAI;IACJ,OAAO;IACP,KAAK;IACL,SAAS;IACT,IAAI;IACJ,MAAM;IACN,OAAO;IACP,KAAK;IACL,OAAO;IACP,OAAO;IACP,MA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;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,CAAA;IACxF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,OAAO,mBAAmB,EAAE,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { PluginHookDefinition } from '../../types/plugin/index.js';
2
+ import type { Logger } from '../../utils/logger.js';
3
+ import { type ShellHookOptions } from '../shell-hook.js';
4
+ import { type HookModuleScan } from './scan.js';
5
+ /** What a hook has to answer in, as the module is told by `next.budget`. */
6
+ export declare const HOOK_MODULE_BUDGET_MS = 10000;
7
+ /**
8
+ * The most time one dispatch may take in all, calls on `$` included, as a
9
+ * multiple of the budget. The budget itself stands still while a call is
10
+ * outstanding; this is what keeps a chain of calls from holding a hook open.
11
+ */
12
+ export declare const HOOK_MODULE_CEILING_FACTOR = 6;
13
+ /** How long a `.catch` has to answer once its hook overran. */
14
+ export declare const HOOK_MODULE_CATCH_MS = 1000;
15
+ /** The worker as the host sees it, so a test can stand in for it. */
16
+ export interface HookModuleTransport {
17
+ post(message: unknown): void;
18
+ onMessage(listener: (message: any) => void): void;
19
+ /** Called once when the worker is gone, with why. */
20
+ onExit(listener: (reason: string) => void): void;
21
+ terminate(): Promise<void>;
22
+ }
23
+ export type HookModuleTransportFactory = () => HookModuleTransport;
24
+ /** The clock the budgets run on. A test drives its own. */
25
+ export interface HookModuleClock {
26
+ now(): number;
27
+ setTimeout(callback: () => void, ms: number): unknown;
28
+ clearTimeout(handle: unknown): void;
29
+ }
30
+ /** A worker thread running {@link HOOK_WORKER_SOURCE}. It never keeps the process alive. */
31
+ export declare const workerTransport: HookModuleTransportFactory;
32
+ export interface StartHookModuleOptions {
33
+ readonly plugin: {
34
+ readonly name: string;
35
+ /** The plugin's folder. */
36
+ readonly root: string;
37
+ /** The folder kept for the plugin's data (`NAMZU_PLUGIN_DATA`). */
38
+ readonly dataDir?: string;
39
+ };
40
+ /** The module, relative to the plugin. */
41
+ readonly entry: string;
42
+ readonly projectDir: string;
43
+ /** How an event becomes the input a hook reads; the same options a command hook gets. */
44
+ readonly shell: ShellHookOptions;
45
+ readonly log: Logger;
46
+ /** The scan, when the caller has just made one. Read again otherwise. */
47
+ readonly scan?: HookModuleScan;
48
+ /** The plugin's options. Empty until a plugin can ask for some. */
49
+ readonly options?: Readonly<Record<string, unknown>>;
50
+ readonly budgetMs?: number;
51
+ readonly catchMs?: number;
52
+ readonly clock?: HookModuleClock;
53
+ readonly transport?: HookModuleTransportFactory;
54
+ readonly environment?: Readonly<Record<string, string | undefined>>;
55
+ readonly fetch?: typeof fetch;
56
+ /** Called once, with the reason, when the module stops running for any cause but being disposed. */
57
+ readonly onUnload?: (message: string) => void;
58
+ }
59
+ export interface HookModuleHandle {
60
+ readonly scan: HookModuleScan;
61
+ readonly status: 'running' | 'unloaded';
62
+ /** Why the module is not running, when it is not. */
63
+ readonly message?: string;
64
+ /** The hooks to attach to the plugin manager. */
65
+ readonly hooks: readonly PluginHookDefinition[];
66
+ /** End the worker. Safe to call again. */
67
+ dispose(): Promise<void>;
68
+ }
69
+ /**
70
+ * Start the hooks module of one plugin: read it, and run it in a worker of its
71
+ * own. The result lists the hooks to attach. A module that is refused, throws
72
+ * where it loads or registers nothing that runs here is reported in `message`
73
+ * and runs nothing; the plugin's other hooks are not touched.
74
+ *
75
+ * The worker is started when the first event it hooks arrives, not before, so a
76
+ * plugin that is enabled and never reaches one of its events costs nothing.
77
+ */
78
+ export declare function startHookModule(options: StartHookModuleOptions): Promise<HookModuleHandle>;
79
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/plugin/hook-module/host.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,oBAAoB,EAEpB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,KAAK,EAAE,MAAM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