dsh-auto-review 0.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 (84) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +201 -0
  3. package/README.es.md +226 -0
  4. package/README.hi.md +226 -0
  5. package/README.md +226 -0
  6. package/README.pt.md +226 -0
  7. package/README.zh.md +226 -0
  8. package/cordis.patch.yml +27 -0
  9. package/lib/client.js +494 -0
  10. package/lib/client.js.map +1 -0
  11. package/lib/events-CFl6CHZi.js +344 -0
  12. package/lib/index.js +5305 -0
  13. package/lib/invariant.js +223 -0
  14. package/lib/types/client/ReviewPanel.d.ts +29 -0
  15. package/lib/types/client/ReviewPanel.d.ts.map +1 -0
  16. package/lib/types/client/ReviewPanel.js +63 -0
  17. package/lib/types/client/ReviewPanel.js.map +1 -0
  18. package/lib/types/client/index.d.ts +31 -0
  19. package/lib/types/client/index.d.ts.map +1 -0
  20. package/lib/types/client/index.js +51 -0
  21. package/lib/types/client/index.js.map +1 -0
  22. package/lib/types/client/locales.d.ts +49 -0
  23. package/lib/types/client/locales.d.ts.map +1 -0
  24. package/lib/types/client/locales.js +82 -0
  25. package/lib/types/client/locales.js.map +1 -0
  26. package/lib/types/client/present.d.ts +25 -0
  27. package/lib/types/client/present.d.ts.map +1 -0
  28. package/lib/types/client/present.js +36 -0
  29. package/lib/types/client/present.js.map +1 -0
  30. package/lib/types/client/styles.d.ts +9 -0
  31. package/lib/types/client/styles.d.ts.map +1 -0
  32. package/lib/types/client/styles.js +130 -0
  33. package/lib/types/client/styles.js.map +1 -0
  34. package/lib/types/config.d.ts +200 -0
  35. package/lib/types/config.d.ts.map +1 -0
  36. package/lib/types/config.js +154 -0
  37. package/lib/types/config.js.map +1 -0
  38. package/lib/types/events.d.ts +347 -0
  39. package/lib/types/events.d.ts.map +1 -0
  40. package/lib/types/events.js +369 -0
  41. package/lib/types/events.js.map +1 -0
  42. package/lib/types/index.d.ts +26 -0
  43. package/lib/types/index.d.ts.map +1 -0
  44. package/lib/types/index.js +26 -0
  45. package/lib/types/index.js.map +1 -0
  46. package/lib/types/invariant.d.ts +28 -0
  47. package/lib/types/invariant.d.ts.map +1 -0
  48. package/lib/types/invariant.js +306 -0
  49. package/lib/types/invariant.js.map +1 -0
  50. package/lib/types/messages.d.ts +38 -0
  51. package/lib/types/messages.d.ts.map +1 -0
  52. package/lib/types/messages.js +65 -0
  53. package/lib/types/messages.js.map +1 -0
  54. package/lib/types/projection-types.d.ts +61 -0
  55. package/lib/types/projection-types.d.ts.map +1 -0
  56. package/lib/types/projection-types.js +8 -0
  57. package/lib/types/projection-types.js.map +1 -0
  58. package/lib/types/projection.d.ts +93 -0
  59. package/lib/types/projection.d.ts.map +1 -0
  60. package/lib/types/projection.js +197 -0
  61. package/lib/types/projection.js.map +1 -0
  62. package/lib/types/review.d.ts +141 -0
  63. package/lib/types/review.d.ts.map +1 -0
  64. package/lib/types/review.js +389 -0
  65. package/lib/types/review.js.map +1 -0
  66. package/lib/types/runtime.d.ts +160 -0
  67. package/lib/types/runtime.d.ts.map +1 -0
  68. package/lib/types/runtime.js +486 -0
  69. package/lib/types/runtime.js.map +1 -0
  70. package/package.json +132 -0
  71. package/src/client/ReviewPanel.tsx +164 -0
  72. package/src/client/index.ts +72 -0
  73. package/src/client/locales.ts +87 -0
  74. package/src/client/present.ts +58 -0
  75. package/src/client/styles.ts +131 -0
  76. package/src/config.ts +346 -0
  77. package/src/events.ts +553 -0
  78. package/src/index.ts +28 -0
  79. package/src/invariant.ts +326 -0
  80. package/src/messages.ts +91 -0
  81. package/src/projection-types.ts +61 -0
  82. package/src/projection.ts +224 -0
  83. package/src/review.ts +428 -0
  84. package/src/runtime.ts +562 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Host projection unit for the `autoReview` panel value: folds the log-only
3
+ * `autoReview/*` events into one wire-JSON whole value the browser review
4
+ * panel reads via `useProjection('autoReview')`. Pure mathematics only — the
5
+ * framework owns subscriptions, watermarks, change feeds, and persistence.
6
+ * The fold mirrors the `events.ts` pure folds (budgets, statistics, denials).
7
+ * @module dsh-auto-review/projection
8
+ */
9
+ import { z } from 'zod';
10
+ /** How many verdict rows the panel carries. */
11
+ const RECENT_CAP = 8;
12
+ /** How many approve candidates the panel offers. */
13
+ const DENIES_CAP = 5;
14
+ const VERDICT_VIEW_SCHEMA = z.object({
15
+ reviewId: z.string(),
16
+ toolName: z.string(),
17
+ at: z.number(),
18
+ durationMs: z.number().int().nonnegative(),
19
+ decision: z.union([z.literal('allow'), z.literal('deny')]).optional(),
20
+ riskLevel: z.union([z.literal('low'), z.literal('medium'), z.literal('high')]).optional(),
21
+ escalation: z.literal('risk-policy').optional(),
22
+ fallback: z.string().optional(),
23
+ outcome: z.union([z.literal('allowed-once'), z.literal('rejected'), z.literal('cancelled'), z.literal('unavailable')]).optional(),
24
+ reason: z.string().optional(),
25
+ });
26
+ const DENY_VIEW_SCHEMA = z.object({
27
+ reviewId: z.string(),
28
+ toolName: z.string(),
29
+ reason: z.string().optional(),
30
+ });
31
+ const CIRCUIT_VIEW_SCHEMA = z.object({
32
+ action: z.union([z.literal('delegate'), z.literal('reject'), z.literal('abort-turn')]),
33
+ trip: z.object({
34
+ kind: z.union([z.literal('consecutive'), z.literal('window')]),
35
+ count: z.number().int().positive(),
36
+ }),
37
+ toolName: z.string(),
38
+ }).nullable();
39
+ /** Strict wire schema — validates the `view` output before it leaves the host. */
40
+ export const AUTO_REVIEW_PROJECTION_SCHEMA = z.object({
41
+ enabled: z.boolean(),
42
+ verdictsUsed: z.number().int().nonnegative(),
43
+ failuresUsed: z.number().int().nonnegative(),
44
+ allows: z.number().int().nonnegative(),
45
+ denies: z.number().int().nonnegative(),
46
+ fallbacks: z.number().int().nonnegative(),
47
+ neverRejects: z.number().int().nonnegative(),
48
+ avgDurationMs: z.number().int().nonnegative(),
49
+ circuit: CIRCUIT_VIEW_SCHEMA,
50
+ recent: z.array(VERDICT_VIEW_SCHEMA),
51
+ recentDenies: z.array(DENY_VIEW_SCHEMA),
52
+ });
53
+ /**
54
+ * State for the empty log. `enabled` starts at the resolved
55
+ * `enableByDefault` — the projection cannot know the plugin config on its
56
+ * own, so the unit is built per mount by {@link makeAutoReviewProjection}.
57
+ * @param enabledByDefault - the resolved `enableByDefault` config value.
58
+ */
59
+ export function initAutoReviewProjection(enabledByDefault) {
60
+ return {
61
+ enabled: enabledByDefault,
62
+ turnOpen: false,
63
+ verdictsUsed: 0,
64
+ failuresUsed: 0,
65
+ allows: 0,
66
+ denies: 0,
67
+ fallbacks: 0,
68
+ neverRejects: 0,
69
+ durationSum: 0,
70
+ decided: 0,
71
+ circuit: null,
72
+ recent: [],
73
+ recentDenies: [],
74
+ };
75
+ }
76
+ /** One verdict event as its panel row. */
77
+ function verdictView(data, at) {
78
+ const view = {
79
+ reviewId: String(data.reviewId),
80
+ toolName: data.toolName,
81
+ at,
82
+ durationMs: data.durationMs,
83
+ };
84
+ if (data.decision !== undefined)
85
+ view.decision = data.decision;
86
+ if (data.riskLevel !== undefined)
87
+ view.riskLevel = data.riskLevel;
88
+ if (data.escalation !== undefined)
89
+ view.escalation = data.escalation;
90
+ if (data.fallback !== undefined)
91
+ view.fallback = data.fallback;
92
+ if (data.outcome !== undefined)
93
+ view.outcome = data.outcome;
94
+ if (data.reason !== undefined)
95
+ view.reason = data.reason;
96
+ return view;
97
+ }
98
+ /** One denial event as its approve row. */
99
+ function denyView(data) {
100
+ const view = {
101
+ reviewId: String(data.reviewId),
102
+ toolName: data.toolName,
103
+ };
104
+ if (data.reason !== undefined)
105
+ view.reason = data.reason;
106
+ return view;
107
+ }
108
+ /**
109
+ * Pure transition: previous state + one committed event → next state.
110
+ * Uninterested events return the same state reference.
111
+ * @param state - the state covering all prior events.
112
+ * @param event - the next committed session event.
113
+ * @returns the next state (same reference when the event is not this unit's).
114
+ */
115
+ export function applyAutoReview(state, event) {
116
+ switch (event.type) {
117
+ case 'turn/start':
118
+ return state.turnOpen
119
+ ? state
120
+ : { ...state, turnOpen: true, verdictsUsed: 0, failuresUsed: 0, circuit: null };
121
+ case 'turn/end':
122
+ return state.turnOpen ? { ...state, turnOpen: false } : state;
123
+ case 'autoReview/state':
124
+ return state.enabled === event.data.enabled ? state : { ...state, enabled: event.data.enabled };
125
+ case 'autoReview/circuit':
126
+ return {
127
+ ...state,
128
+ circuit: { action: event.data.action, trip: event.data.trip, toolName: event.data.toolName },
129
+ };
130
+ case 'autoReview/rejection':
131
+ return { ...state, neverRejects: state.neverRejects + 1 };
132
+ case 'autoReview/verdict': {
133
+ const data = event.data;
134
+ const decision = data.decision !== undefined;
135
+ const failure = data.fallback !== undefined && data.fallback !== 'cancelled';
136
+ const denial = data.decision === 'deny' || data.escalation === 'risk-policy';
137
+ const row = verdictView(data, event.time);
138
+ return {
139
+ ...state,
140
+ verdictsUsed: state.turnOpen && decision ? state.verdictsUsed + 1 : state.verdictsUsed,
141
+ failuresUsed: state.turnOpen && failure ? state.failuresUsed + 1 : state.failuresUsed,
142
+ allows: state.allows + (data.decision === 'allow' ? 1 : 0),
143
+ denies: state.denies + (data.decision === 'deny' ? 1 : 0),
144
+ fallbacks: state.fallbacks + (decision ? 0 : 1),
145
+ durationSum: state.durationSum + (decision ? data.durationMs : 0),
146
+ decided: state.decided + (decision ? 1 : 0),
147
+ recent: [row, ...state.recent].slice(0, RECENT_CAP),
148
+ recentDenies: denial
149
+ ? [denyView(data), ...state.recentDenies].slice(0, DENIES_CAP)
150
+ : state.recentDenies,
151
+ };
152
+ }
153
+ default:
154
+ return state;
155
+ }
156
+ }
157
+ /** State → wire payload (the read-side projection). */
158
+ export function viewAutoReview(state) {
159
+ return {
160
+ enabled: state.enabled,
161
+ verdictsUsed: state.verdictsUsed,
162
+ failuresUsed: state.failuresUsed,
163
+ allows: state.allows,
164
+ denies: state.denies,
165
+ fallbacks: state.fallbacks,
166
+ neverRejects: state.neverRejects,
167
+ avgDurationMs: state.decided === 0 ? 0 : Math.round(state.durationSum / state.decided),
168
+ circuit: state.circuit,
169
+ recent: state.recent,
170
+ recentDenies: state.recentDenies,
171
+ };
172
+ }
173
+ /**
174
+ * Build the registered unit for one mount. The unit's initial `enabled` is
175
+ * the mount's resolved `enableByDefault` (the pure `init` cannot see plugin
176
+ * config otherwise), and the panel therefore reports the same switch state
177
+ * the answerer applies. Registrants sharing the `autoReview` key share one
178
+ * unit; the first mount's default wins, which only matters for a double
179
+ * mount with conflicting `enableByDefault` values.
180
+ * @param enabledByDefault - the resolved `enableByDefault` config value.
181
+ * @returns the projection unit for `ctx.sessionProjections.register`.
182
+ */
183
+ export function makeAutoReviewProjection(enabledByDefault) {
184
+ return {
185
+ key: 'autoReview',
186
+ // zod v4's `.optional()` output carries `| undefined`, which exact-optional
187
+ // property types reject; the runtime validation is what matters on the wire.
188
+ schema: AUTO_REVIEW_PROJECTION_SCHEMA,
189
+ init: () => initAutoReviewProjection(enabledByDefault),
190
+ apply: applyAutoReview,
191
+ view: viewAutoReview,
192
+ // v2: `init.enabled` follows `enableByDefault` (was hardcoded true) and the
193
+ // wire gained the cumulative `neverRejects` counter.
194
+ stateVersion: 2,
195
+ };
196
+ }
197
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../src/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,+CAA+C;AAC/C,MAAM,UAAU,GAAG,CAAC,CAAA;AACpB,oDAAoD;AACpD,MAAM,UAAU,GAAG,CAAC,CAAA;AAEpB,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,C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H,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAyB;IAChE,OAAO;QACL,GAAG,EAAE,YAAY;QACjB,4EAA4E;QAC5E,6EAA6E;QAC7E,MAAM,EAAE,6BAAmH;QAC3H,IAAI,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,gBAAgB,CAAC;QACtD,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,cAAc;QACpB,4EAA4E;QAC5E,qDAAqD;QACrD,YAAY,EAAE,CAAC;KAChB,CAAA;AACH,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The reviewer subagent: one-shot in-process child with a read-only tool
3
+ * allow-list and a structured verdict schema, raced against the configured
4
+ * timeout and the request's cancellation signal. Any failure resolves to a
5
+ * {@link ReviewFailure} — the caller applies the fallback policy, never a
6
+ * grant (fail closed by default).
7
+ * @module dsh-auto-review/review
8
+ */
9
+ import type { Context } from '@deepseek-ai/cordis';
10
+ import type { CallId } from '@deepseek-ai/dsh-llm';
11
+ import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session';
12
+ import type { ApprovalRequest } from '@deepseek-ai/dsh-user-approval';
13
+ import { type ObjectJsonSchema } from '@deepseek-ai/dsh-tools';
14
+ import type { AutoReviewFallback } from './events.ts';
15
+ import { AutoReviewCircuitId, AutoReviewRejectionId, AutoReviewVerdictId } from './events.ts';
16
+ import type { ContextBudgetConfig, ResolvedConfig, RiskLevel } from './config.ts';
17
+ /** A reviewer verdict, validated against the closed decision vocabulary. */
18
+ export interface ReviewerVerdict {
19
+ readonly decision: 'allow' | 'deny';
20
+ readonly reason: string;
21
+ readonly riskLevel?: RiskLevel;
22
+ /** The reviewer child's session id (its own log is auditable). */
23
+ readonly reviewerSessionId?: SessionId;
24
+ /** The explicitly configured reviewer model, when one was set. */
25
+ readonly model?: string;
26
+ }
27
+ /**
28
+ * A review that produced no verdict. The caller maps the failure to the
29
+ * configured fallback policy.
30
+ */
31
+ export interface ReviewFailure {
32
+ readonly fallback: AutoReviewFallback;
33
+ readonly error: string;
34
+ readonly reviewerSessionId?: SessionId;
35
+ readonly model?: string;
36
+ }
37
+ /** The closed result of one review attempt. */
38
+ export type ReviewResolution = ReviewerVerdict | ReviewFailure;
39
+ /** Distinguish a verdict resolution from a failure. */
40
+ export declare function isReviewFailure(resolution: ReviewResolution): resolution is ReviewFailure;
41
+ /** Object-rooted verdict schema enforced on the child's structured_output capture. */
42
+ export declare const VERDICT_SCHEMA: ObjectJsonSchema;
43
+ /**
44
+ * Recursively redact sensitive values from a JSON value: any object key
45
+ * matching {@link SENSITIVE_KEY_PATTERN} has its value replaced.
46
+ * @param value - the detached JSON value to sanitize.
47
+ * @returns a detached copy with sensitive values redacted.
48
+ */
49
+ export declare function sanitizeArguments(value: unknown): unknown;
50
+ /**
51
+ * The already-presented call arguments, parsed and key-redacted, as pretty
52
+ * JSON — the raw material for both the reviewer prompt section and the
53
+ * `arguments` risk-rule field.
54
+ * @param events - the requesting session's log.
55
+ * @param callId - the call to render.
56
+ * @returns the sanitized JSON text, or undefined when the log lacks a parseable call.
57
+ */
58
+ export declare function sanitizedArgumentsText(events: readonly SessionEvent[], callId: CallId): string | undefined;
59
+ /**
60
+ * Render the tool-call context for the reviewer: the already-streamed call
61
+ * arguments (parsed, redacted, truncated) or a note when the log lacks them.
62
+ * @param events - the requesting session's log.
63
+ * @param callId - the call to render.
64
+ * @param maxChars - the preview cap (shared with reason truncation).
65
+ * @returns the prompt section text.
66
+ */
67
+ export declare function renderCallContext(events: readonly SessionEvent[], callId: CallId | undefined, maxChars: number): string;
68
+ /**
69
+ * Build the compact-transcript section for the reviewer: the tail of the
70
+ * session's user/assistant messages and tool calls/results, most recent
71
+ * last, bounded by {@link ContextBudgetConfig}. `turns: 0` yields an empty
72
+ * section. Tool-call arguments and tool-result text enter verbatim (they are
73
+ * already-presented transcript content); the presented call of the pending
74
+ * request is redacted separately in {@link renderCallContext}.
75
+ * @param events - the requesting session's log.
76
+ * @param budget - how much context to include.
77
+ * @returns the prompt section text (empty when disabled).
78
+ */
79
+ export declare function buildContextSection(events: readonly SessionEvent[], budget: ContextBudgetConfig): string;
80
+ /** Context of a pending human override, passed into the reviewer prompt. */
81
+ export interface OverrideContext {
82
+ readonly reviewId: AutoReviewVerdictId;
83
+ readonly toolName: string;
84
+ }
85
+ /**
86
+ * Truncate a string to a character budget without cutting surrogate pairs.
87
+ * @param text - the string to cap.
88
+ * @param maxChars - the positive budget.
89
+ * @returns the capped string.
90
+ */
91
+ export declare function truncate(text: string, maxChars: number): string;
92
+ /**
93
+ * Build the reviewer prompt: role, the pending request's tool/reason/context/
94
+ * workspace, the resolved risk rules, the ruling policy text, the optional
95
+ * human-override context, and the verdict contract.
96
+ * @param request - the pending approval request.
97
+ * @param config - resolved config (rules, guidance, budgets).
98
+ * @param override - a pending human one-shot override, when one applies.
99
+ * @returns the exact prompt text block.
100
+ */
101
+ export declare function buildReviewPrompt(request: ApprovalRequest, config: ResolvedConfig, override?: OverrideContext): string;
102
+ /**
103
+ * Validate the provider-validated structured capture against the closed
104
+ * verdict vocabulary. The subagent seam validates against the schema, but its
105
+ * result is typed `unknown`; this is the boundary that narrows it.
106
+ * @param value - the captured structured value.
107
+ * @param reasonMaxChars - the reason cap.
108
+ * @returns the verdict, or undefined when the value cannot be a verdict.
109
+ */
110
+ export declare function parseVerdict(value: unknown, reasonMaxChars: number): ReviewerVerdict | undefined;
111
+ /**
112
+ * Run one review attempt: start a one-shot reviewer child on the configured
113
+ * provider, await its structured verdict, and race both the configured
114
+ * timeout and the request signal. Every failure path resolves to a
115
+ * {@link ReviewFailure} — never to a grant.
116
+ * @param ctx - the plugin context (`ctx.subagents` and the request's parent agent).
117
+ * @param config - resolved config (provider, timeout, tools, model, budgets).
118
+ * @param request - the pending approval request (parent, signal, and evidence).
119
+ * @param reviewerSessions - the runtime's live reviewer session ids, so the
120
+ * answerer can refuse the child's own approval asks while the review runs.
121
+ * @param override - a pending human one-shot override, when one applies.
122
+ * @returns the verdict or the failure.
123
+ */
124
+ export declare function runReview(ctx: Context, config: ResolvedConfig, request: ApprovalRequest, reviewerSessions: Set<SessionId>, override?: OverrideContext): Promise<ReviewResolution>;
125
+ /**
126
+ * Mint one verdict id. Wrapped for testability (audit uniqueness is a UUID).
127
+ * @returns a fresh branded id.
128
+ */
129
+ export declare function newVerdictId(): AutoReviewVerdictId;
130
+ /**
131
+ * Mint one circuit-trip id. Wrapped for testability (audit uniqueness is a UUID).
132
+ * @returns a fresh branded id.
133
+ */
134
+ export declare function newCircuitId(): AutoReviewCircuitId;
135
+ /**
136
+ * Mint one hard-disable rejection id. Wrapped for testability (audit
137
+ * uniqueness is a UUID).
138
+ * @returns a fresh branded id.
139
+ */
140
+ export declare function newRejectionId(): AutoReviewRejectionId;
141
+ //# sourceMappingURL=review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/review.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,sBAAsB,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAErE,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAA;AAChH,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEjF,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAA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