@shardworks/claude-code-apparatus 0.1.270 → 0.1.271
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babysitter.d.ts +10 -153
- package/dist/babysitter.d.ts.map +1 -1
- package/dist/babysitter.js +11 -342
- package/dist/babysitter.js.map +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +165 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +357 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -19,15 +19,21 @@ import type { SessionChunk, SessionTerminationTag } from '@shardworks/animator-a
|
|
|
19
19
|
* Detect a rate-limit signature on an NDJSON message from the claude
|
|
20
20
|
* `--output-format stream-json` stream.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
* - `msg.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* One branch, evidence-driven:
|
|
23
|
+
* - `msg.error` (top-level, peer of `message`) matches the
|
|
24
|
+
* rate-limit pattern. Claude's observed emission is
|
|
25
|
+
* `{type:"assistant", message:{...}, error:"rate_limit"}` with no
|
|
26
|
+
* `is_error` flag, no distinguishing `subtype`, no signal in
|
|
27
|
+
* `subtype`/`is_error` shape — so the only reliable tag is the
|
|
28
|
+
* top-level `error` value matching the rate-limit pattern.
|
|
26
29
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* Two earlier speculative branches (`subtype` containing `rate_limit`,
|
|
31
|
+
* and `is_error: true` carrying error text) were removed because no
|
|
32
|
+
* live provider emission was ever observed against them; they were
|
|
33
|
+
* inherited from an early speculative cascade. If a future provider
|
|
34
|
+
* shape requires either, add it back with a real example.
|
|
35
|
+
*
|
|
36
|
+
* Returns null when the message does not indicate rate limiting.
|
|
31
37
|
*/
|
|
32
38
|
export declare function detectRateLimitFromNdjson(msg: Record<string, unknown>): SessionTerminationTag | null;
|
|
33
39
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAIV,YAAY,EACZ,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAIV,YAAY,EACZ,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AAyBxC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,qBAAqB,GAAG,IAAI,CAU9B;AAID;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAiBnG;AA0CD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAWjD;;AAED,wBAA0C;AAI1C,uDAAuD;AACvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;CACxC;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,EAAE;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC5C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;CACxC,GACA,YAAY,EAAE,CAyDhB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAC9C,MAAM,CAgBR"}
|
package/dist/index.js
CHANGED
|
@@ -16,50 +16,50 @@
|
|
|
16
16
|
import { launchDetached } from "./detached.js";
|
|
17
17
|
// ── Rate-limit detection ────────────────────────────────────────────
|
|
18
18
|
/**
|
|
19
|
-
* Regex matching
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* Regex matching the canonical claude rate-limit emission. Applied to
|
|
20
|
+
* the top-level `error` field of an NDJSON message.
|
|
21
|
+
*
|
|
22
|
+
* Underscore is included alongside hyphen and whitespace because claude
|
|
23
|
+
* emits the canonical token `rate_limit` (not `rate-limit`) on the
|
|
24
|
+
* top-level `error` field of an assistant termination message.
|
|
25
|
+
*
|
|
26
|
+
* The detector is intentionally evidence-driven and narrow: branches
|
|
27
|
+
* are added when a real provider emission is observed, not pre-emptively.
|
|
28
|
+
* Speculative coverage burned us before (a `result`-text branch matched
|
|
29
|
+
* an assistant's prose summary of a prior rate-limit and false-paused
|
|
30
|
+
* the guild; a stderr/exit-code cascade did the same on a generic
|
|
31
|
+
* non-zero exit), so the discipline is to keep this narrow and add
|
|
32
|
+
* branches only when their input shape is observed in the wild.
|
|
25
33
|
*/
|
|
26
|
-
const RATE_LIMIT_ERROR_TEXT_PATTERN = /(rate[
|
|
34
|
+
const RATE_LIMIT_ERROR_TEXT_PATTERN = /(rate[-_\s]?limit|429\b|usage[-_\s]?limit|quota[-_\s]?exceeded|too\s+many\s+requests)/i;
|
|
27
35
|
/**
|
|
28
36
|
* Detect a rate-limit signature on an NDJSON message from the claude
|
|
29
37
|
* `--output-format stream-json` stream.
|
|
30
38
|
*
|
|
31
|
-
*
|
|
32
|
-
* - `msg.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
39
|
+
* One branch, evidence-driven:
|
|
40
|
+
* - `msg.error` (top-level, peer of `message`) matches the
|
|
41
|
+
* rate-limit pattern. Claude's observed emission is
|
|
42
|
+
* `{type:"assistant", message:{...}, error:"rate_limit"}` with no
|
|
43
|
+
* `is_error` flag, no distinguishing `subtype`, no signal in
|
|
44
|
+
* `subtype`/`is_error` shape — so the only reliable tag is the
|
|
45
|
+
* top-level `error` value matching the rate-limit pattern.
|
|
46
|
+
*
|
|
47
|
+
* Two earlier speculative branches (`subtype` containing `rate_limit`,
|
|
48
|
+
* and `is_error: true` carrying error text) were removed because no
|
|
49
|
+
* live provider emission was ever observed against them; they were
|
|
50
|
+
* inherited from an early speculative cascade. If a future provider
|
|
51
|
+
* shape requires either, add it back with a real example.
|
|
35
52
|
*
|
|
36
|
-
* Returns null when the message does not indicate rate limiting.
|
|
37
|
-
* previous `msg.type === 'result'` + prose-text branch was removed
|
|
38
|
-
* because it matched an assistant's summary of a prior rate-limit event,
|
|
39
|
-
* producing false-positive pauses.
|
|
53
|
+
* Returns null when the message does not indicate rate limiting.
|
|
40
54
|
*/
|
|
41
55
|
export function detectRateLimitFromNdjson(msg) {
|
|
42
|
-
|
|
43
|
-
if (subtype && /rate[-_ ]?limit/i.test(subtype)) {
|
|
56
|
+
if (typeof msg.error === 'string' && RATE_LIMIT_ERROR_TEXT_PATTERN.test(msg.error)) {
|
|
44
57
|
return {
|
|
45
58
|
kind: 'rate-limit',
|
|
46
59
|
source: 'ndjson-result',
|
|
47
|
-
detail:
|
|
60
|
+
detail: msg.error.slice(0, 200),
|
|
48
61
|
};
|
|
49
62
|
}
|
|
50
|
-
if (msg.is_error === true) {
|
|
51
|
-
const errText = (typeof msg.error === 'string' ? msg.error : undefined) ??
|
|
52
|
-
(typeof msg.message?.error === 'string'
|
|
53
|
-
? (msg.message.error)
|
|
54
|
-
: undefined);
|
|
55
|
-
if (errText && RATE_LIMIT_ERROR_TEXT_PATTERN.test(errText)) {
|
|
56
|
-
return {
|
|
57
|
-
kind: 'rate-limit',
|
|
58
|
-
source: 'ndjson-result',
|
|
59
|
-
detail: errText.slice(0, 200),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
// ── Output extraction ───────────────────────────────────────────────
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,uEAAuE;AAEvE
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,uEAAuE;AAEvE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,6BA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;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,OAA+C;IAE/C,IAAI,UAAkB,CAAC;IACvB,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;QAChD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAEtC,IAAI,CAAC,IAAI;YAAE,SAAS;QAEpB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babysitter runtime toolkit — single-purpose primitives shared by the
|
|
3
|
+
* orchestrator and proxy in `babysitter.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Each export is a small, self-contained piece: stdin parsing, retrying
|
|
6
|
+
* HTTP, the DLQ writer, the SQLite trio, the lifecycle reporters, and
|
|
7
|
+
* the stderr redirector. The orchestrator composes them; this module
|
|
8
|
+
* does not know about the orchestrator.
|
|
9
|
+
*
|
|
10
|
+
* See: docs/architecture/detached-sessions.md
|
|
11
|
+
*/
|
|
12
|
+
import { type StreamJsonResult } from './index.ts';
|
|
13
|
+
import type { SessionTerminationTag } from '@shardworks/animator-apparatus';
|
|
14
|
+
/** A serialized tool definition as received in the babysitter config. */
|
|
15
|
+
export interface SerializedTool {
|
|
16
|
+
/** Tool name (e.g. 'writ-list'). */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Tool description. */
|
|
19
|
+
description: string;
|
|
20
|
+
/** JSON Schema for the tool's input parameters. */
|
|
21
|
+
params: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* HTTP method the guild tool server routes this tool under. The MCP proxy
|
|
24
|
+
* uses this to avoid POSTing to a GET-only read-tool route (which would
|
|
25
|
+
* 404). Derived from the tool's `permission` by `permissionToMethod()`.
|
|
26
|
+
*/
|
|
27
|
+
method: 'GET' | 'POST' | 'DELETE';
|
|
28
|
+
}
|
|
29
|
+
/** Config written to the babysitter's stdin by the spawning process. */
|
|
30
|
+
export interface BabysitterConfig {
|
|
31
|
+
sessionId: string;
|
|
32
|
+
guildToolUrl: string;
|
|
33
|
+
dbPath: string;
|
|
34
|
+
logDir: string;
|
|
35
|
+
claudeArgs: string[];
|
|
36
|
+
cwd: string;
|
|
37
|
+
env: Record<string, string>;
|
|
38
|
+
prompt: string;
|
|
39
|
+
tools: SerializedTool[];
|
|
40
|
+
startedAt: string;
|
|
41
|
+
provider: string;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
|
+
/** Temp directory for the system prompt file. Cleaned up in finally block. */
|
|
44
|
+
systemPromptTmpDir?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Walk an error's cause chain looking for a retryable error code.
|
|
48
|
+
* Returns the first retryable code found, or null if none.
|
|
49
|
+
* Caps traversal depth to prevent infinite loops from circular cause chains.
|
|
50
|
+
*/
|
|
51
|
+
export declare function findRetryableCode(err: unknown, maxDepth?: number): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Read the babysitter config from stdin.
|
|
54
|
+
*
|
|
55
|
+
* Reads stdin to completion, parses the JSON, and validates required fields.
|
|
56
|
+
* The spawning process writes config and closes the write end.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readConfigFromStdin(stream?: NodeJS.ReadableStream): Promise<BabysitterConfig>;
|
|
59
|
+
export declare function callGuildHttpApi(url: string, sessionId: string, body: unknown, timeoutMs?: number, method?: 'GET' | 'POST' | 'DELETE'): Promise<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* Write a payload to the Dead Letter Queue.
|
|
62
|
+
*
|
|
63
|
+
* Creates the DLQ directory if it doesn't exist. Writes the payload as
|
|
64
|
+
* pretty-printed JSON. Used as a fallback when the guild HTTP API is
|
|
65
|
+
* unreachable for lifecycle calls.
|
|
66
|
+
*/
|
|
67
|
+
export declare function writeToDlq(cwd: string, filename: string, payload: unknown): void;
|
|
68
|
+
/** Minimal interface for the SQLite database used by the babysitter. */
|
|
69
|
+
export interface TranscriptDb {
|
|
70
|
+
/** Write a transcript entry (id, content JSON). */
|
|
71
|
+
writeTranscript(sessionId: string, content: string): void;
|
|
72
|
+
/** Close the database connection. */
|
|
73
|
+
close(): void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Open the guild's SQLite database for transcript streaming.
|
|
77
|
+
*
|
|
78
|
+
* Creates the database file and table if they don't exist.
|
|
79
|
+
* Enables WAL mode for concurrent read access by other processes
|
|
80
|
+
* (Oculus, CLI queries, other agents).
|
|
81
|
+
*
|
|
82
|
+
* Uses dynamic import() to load better-sqlite3 at runtime. This avoids
|
|
83
|
+
* requiring the native module at import time (beneficial for type-checking
|
|
84
|
+
* and testing).
|
|
85
|
+
*/
|
|
86
|
+
export declare function openTranscriptDb(dbPath: string): Promise<TranscriptDb>;
|
|
87
|
+
/**
|
|
88
|
+
* Initialize a TranscriptDb from a Database constructor.
|
|
89
|
+
*
|
|
90
|
+
* Shared logic between openTranscriptDb() and test injection.
|
|
91
|
+
* Exported for testing — allows injecting a mock Database constructor.
|
|
92
|
+
*/
|
|
93
|
+
export declare function initTranscriptDb(DatabaseConstructor: new (path: string) => {
|
|
94
|
+
pragma(stmt: string): unknown;
|
|
95
|
+
prepare(sql: string): {
|
|
96
|
+
run(...params: unknown[]): void;
|
|
97
|
+
};
|
|
98
|
+
exec(sql: string): void;
|
|
99
|
+
close(): void;
|
|
100
|
+
}, dbPath: string): TranscriptDb;
|
|
101
|
+
/**
|
|
102
|
+
* Write the current transcript to SQLite.
|
|
103
|
+
*/
|
|
104
|
+
export declare function writeTranscript(db: TranscriptDb, sessionId: string, messages: Record<string, unknown>[]): void;
|
|
105
|
+
/**
|
|
106
|
+
* Report "running" status to the guild via the session-running tool.
|
|
107
|
+
*
|
|
108
|
+
* If the guild is unreachable, writes the payload to the DLQ.
|
|
109
|
+
*/
|
|
110
|
+
export declare function reportRunning(config: BabysitterConfig, cancelHandle: Record<string, unknown>, timeoutMs?: number): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the terminal status and error text for a terminated session.
|
|
113
|
+
*
|
|
114
|
+
* Cascade order:
|
|
115
|
+
* 1. A `'cancelled'` override (SIGTERM path) — short-circuits.
|
|
116
|
+
* 2. A `terminationTag` already carried on the StreamJsonResult —
|
|
117
|
+
* set by the NDJSON detection cascade inside
|
|
118
|
+
* `parseStreamJsonMessage` (the only active detector).
|
|
119
|
+
* 3. Generic exit-code mapping (0 → completed, non-zero → failed).
|
|
120
|
+
*
|
|
121
|
+
* Generic non-zero exit codes surface as `'failed'`; the Animator's
|
|
122
|
+
* back-off machine only reacts to structured rate-limit terminals, and
|
|
123
|
+
* exit-code-based detection was retired because it produced
|
|
124
|
+
* false-positive pauses.
|
|
125
|
+
*
|
|
126
|
+
* Returns the payload status, a human-readable error string (only
|
|
127
|
+
* populated for the failed branches), and the tag that informed the
|
|
128
|
+
* decision (if any). The tag is forwarded to the guild so the Animator's
|
|
129
|
+
* back-off machine can disambiguate rate-limit terminations without
|
|
130
|
+
* pattern-matching on error text.
|
|
131
|
+
*/
|
|
132
|
+
export declare function resolveTerminalStatus(result: StreamJsonResult, statusOverride?: 'cancelled'): {
|
|
133
|
+
status: 'completed' | 'failed' | 'cancelled' | 'rate-limited';
|
|
134
|
+
error?: string;
|
|
135
|
+
terminationTag?: SessionTerminationTag;
|
|
136
|
+
};
|
|
137
|
+
/** Maximum number of characters to retain for the diagnostic stderr tail. */
|
|
138
|
+
export declare const STDERR_DIAGNOSTIC_TAIL_LIMIT = 200;
|
|
139
|
+
/**
|
|
140
|
+
* Report the final session result to the guild via the session-record tool.
|
|
141
|
+
*
|
|
142
|
+
* When the resolved terminal status is exactly `'failed'` (non-zero exit,
|
|
143
|
+
* no structured termination tag, no cancel override), attach a passive
|
|
144
|
+
* `terminationDiagnostic: { exitCode, stderrExcerpt? }` to the payload.
|
|
145
|
+
* The diagnostic is informational only — the Animator's back-off
|
|
146
|
+
* machine never consumes it. The stderr excerpt is only present when
|
|
147
|
+
* the caller supplied a non-empty tail.
|
|
148
|
+
*
|
|
149
|
+
* If the guild is unreachable, writes the payload to the DLQ.
|
|
150
|
+
*/
|
|
151
|
+
export declare function reportResult(config: BabysitterConfig, result: StreamJsonResult, transcript: Record<string, unknown>[], timeoutMs?: number, statusOverride?: 'cancelled', stderrTail?: string): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Open a per-session log file and redirect process.stderr.write to it.
|
|
154
|
+
*
|
|
155
|
+
* Creates the logDir (recursive) and opens `<logDir>/<sessionId>.log`
|
|
156
|
+
* for append-writing. Replaces process.stderr.write with a function
|
|
157
|
+
* that calls fs.writeSync on the owned fd. Writes the startup banner
|
|
158
|
+
* as the first line.
|
|
159
|
+
*
|
|
160
|
+
* Returns the owned fd so the caller can close it in a finally block.
|
|
161
|
+
*
|
|
162
|
+
* @internal Exported for testing only.
|
|
163
|
+
*/
|
|
164
|
+
export declare function redirectStderrToFile(logDir: string, sessionId: string): number;
|
|
165
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAI5E,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7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