taskflow-hosts 0.1.8 → 0.2.1
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/README.md +27 -12
- package/dist/child-env.d.ts +6 -0
- package/dist/child-env.d.ts.map +1 -0
- package/dist/child-env.js +43 -0
- package/dist/child-env.js.map +1 -0
- package/dist/claude-runner.d.ts +27 -15
- package/dist/claude-runner.d.ts.map +1 -1
- package/dist/claude-runner.js +163 -31
- package/dist/claude-runner.js.map +1 -1
- package/dist/codex-runner.d.ts +8 -1
- package/dist/codex-runner.d.ts.map +1 -1
- package/dist/codex-runner.js +85 -20
- package/dist/codex-runner.js.map +1 -1
- package/dist/grok-runner.d.ts +133 -0
- package/dist/grok-runner.d.ts.map +1 -0
- package/dist/grok-runner.js +350 -0
- package/dist/grok-runner.js.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/opencode-runner.d.ts +16 -0
- package/dist/opencode-runner.d.ts.map +1 -1
- package/dist/opencode-runner.js +82 -13
- package/dist/opencode-runner.js.map +1 -1
- package/package.json +22 -9
package/dist/codex-runner.js
CHANGED
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
* error sanitization) is delegated to the shared `runSubagentProcess` in
|
|
29
29
|
* taskflow-core, so behavior is uniform across hosts.
|
|
30
30
|
*/
|
|
31
|
-
import { runSubagentProcess, num, unknownAgentResult, } from "taskflow-core";
|
|
31
|
+
import { runSubagentProcess, sanitizeErrorMessage, num, unknownAgentResult, } from "taskflow-core";
|
|
32
32
|
import { emptyUsage } from "taskflow-core";
|
|
33
|
+
import { filteredChildEnv } from "./child-env.js";
|
|
33
34
|
/** Benign codex `error` items that are warnings, not failures. Matched as a
|
|
34
35
|
* prefix/substring so version drift in the message tail still classifies. */
|
|
35
36
|
const BENIGN_ERROR_MARKERS = [
|
|
@@ -63,16 +64,26 @@ export function foldCodexEventLine(acc, line) {
|
|
|
63
64
|
return null;
|
|
64
65
|
}
|
|
65
66
|
let activity = "";
|
|
66
|
-
if (event.type === "turn.completed"
|
|
67
|
+
if (event.type === "turn.completed") {
|
|
68
|
+
acc.terminalSeen = true;
|
|
67
69
|
const u = event.usage;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
if (u) {
|
|
71
|
+
acc.usage.turns++;
|
|
72
|
+
acc.usage.input += num(u.input_tokens);
|
|
73
|
+
acc.usage.output += num(u.output_tokens) + num(u.reasoning_output_tokens);
|
|
74
|
+
acc.usage.cacheRead += num(u.cached_input_tokens);
|
|
75
|
+
// contextTokens is a host-specific point-in-time gauge (NOT additive — excluded from aggregateUsage):
|
|
76
|
+
// each host's formula differs because each accounts for cache differently. Codex's input_tokens
|
|
77
|
+
// already includes cached tokens, so input+output = full last-turn context.
|
|
78
|
+
acc.usage.contextTokens = num(u.input_tokens) + num(u.output_tokens);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (event.type === "turn.failed" || event.type === "error") {
|
|
82
|
+
const message = (typeof event.error?.message === "string" && event.error.message) ||
|
|
83
|
+
(typeof event.message === "string" && event.message) ||
|
|
84
|
+
"codex turn failed";
|
|
85
|
+
acc.fatalError = message;
|
|
86
|
+
activity = `error: ${message}`;
|
|
76
87
|
}
|
|
77
88
|
else if (event.type === "item.completed" || event.type === "item.started") {
|
|
78
89
|
const item = event.item;
|
|
@@ -113,6 +124,9 @@ export function foldCodexEventLine(acc, line) {
|
|
|
113
124
|
export function codexBin() {
|
|
114
125
|
return process.env.PI_TASKFLOW_CODEX_BIN || "codex";
|
|
115
126
|
}
|
|
127
|
+
export function codexChildEnv(source = process.env) {
|
|
128
|
+
return filteredChildEnv(source, ["CODEX_HOME"], ["CODEX_", "OPENAI_", "AZURE_OPENAI_"]);
|
|
129
|
+
}
|
|
116
130
|
/**
|
|
117
131
|
* Map a phase's tool whitelist to a codex sandbox mode. Codex has no per-tool
|
|
118
132
|
* whitelist; it has sandbox policies. The conservative mapping: a phase that
|
|
@@ -141,22 +155,50 @@ export function resolveCodexModel(model) {
|
|
|
141
155
|
return undefined;
|
|
142
156
|
return model;
|
|
143
157
|
}
|
|
158
|
+
/** Map Taskflow/Pi thinking levels to Codex's model_reasoning_effort config. */
|
|
159
|
+
export function resolveCodexThinking(thinking) {
|
|
160
|
+
if (!thinking)
|
|
161
|
+
return undefined;
|
|
162
|
+
const normalized = thinking.trim().toLowerCase();
|
|
163
|
+
if (normalized === "off" || normalized === "none" || normalized === "minimal")
|
|
164
|
+
return "none";
|
|
165
|
+
if (normalized === "max" || normalized === "ultra")
|
|
166
|
+
return "xhigh";
|
|
167
|
+
if (["low", "medium", "high", "xhigh"].includes(normalized))
|
|
168
|
+
return normalized;
|
|
169
|
+
throw new Error(`Unsupported Codex thinking level '${thinking}'. Use off, none, minimal, low, medium, high, xhigh, max, or ultra.`);
|
|
170
|
+
}
|
|
144
171
|
/**
|
|
145
172
|
* Build the full `codex exec` argv from a phase's resolved context — PURE
|
|
146
173
|
* (no process.env, no spawn). Extracted from `runCodexAgentTask` so the host's
|
|
147
174
|
* CLI flag contract is unit-testable in CI without a live codex session.
|
|
148
175
|
*
|
|
149
|
-
* codex exec --json --skip-git-repo-check -s <sandbox>
|
|
176
|
+
* codex exec --json --skip-git-repo-check -s <sandbox>
|
|
177
|
+
* [-m model] [-c model_reasoning_effort=level] [-C cwd] <prompt>
|
|
150
178
|
*/
|
|
151
179
|
export function buildCodexArgs(ctx) {
|
|
152
180
|
const sandbox = sandboxForTools(ctx.tools);
|
|
153
181
|
const codexModel = resolveCodexModel(ctx.model);
|
|
182
|
+
const codexThinking = resolveCodexThinking(ctx.thinking);
|
|
154
183
|
const fullPrompt = ctx.systemPrompt.trim()
|
|
155
184
|
? `${ctx.systemPrompt.trim()}\n\n---\n\nTask: ${ctx.task}`
|
|
156
185
|
: `Task: ${ctx.task}`;
|
|
157
|
-
const args = [
|
|
186
|
+
const args = [
|
|
187
|
+
"exec",
|
|
188
|
+
"--json",
|
|
189
|
+
"--ephemeral",
|
|
190
|
+
"--ignore-user-config",
|
|
191
|
+
"--ignore-rules",
|
|
192
|
+
"--skip-git-repo-check",
|
|
193
|
+
"-c",
|
|
194
|
+
"mcp_servers={}",
|
|
195
|
+
"-s",
|
|
196
|
+
sandbox,
|
|
197
|
+
];
|
|
158
198
|
if (codexModel)
|
|
159
199
|
args.push("-m", codexModel);
|
|
200
|
+
if (codexThinking)
|
|
201
|
+
args.push("-c", `model_reasoning_effort=${codexThinking}`);
|
|
160
202
|
if (ctx.cwd)
|
|
161
203
|
args.push("-C", ctx.cwd);
|
|
162
204
|
args.push(fullPrompt);
|
|
@@ -172,27 +214,48 @@ export async function runCodexAgentTask(defaultCwd, agents, agentName, task, opt
|
|
|
172
214
|
return unknownAgentResult(agentName, task, agents);
|
|
173
215
|
const model = opts.model ?? agent.model;
|
|
174
216
|
const tools = opts.tools ?? agent.tools;
|
|
175
|
-
|
|
217
|
+
const thinking = opts.thinking ?? agent.thinking ?? globalThinking;
|
|
176
218
|
const cwd = opts.cwd ?? defaultCwd;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
219
|
+
let args;
|
|
220
|
+
try {
|
|
221
|
+
args = buildCodexArgs({
|
|
222
|
+
systemPrompt: agent.systemPrompt,
|
|
223
|
+
task,
|
|
224
|
+
model,
|
|
225
|
+
thinking,
|
|
226
|
+
tools,
|
|
227
|
+
cwd,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
const message = sanitizeErrorMessage(error instanceof Error ? error.message : String(error));
|
|
232
|
+
return {
|
|
233
|
+
agent: agentName,
|
|
234
|
+
task,
|
|
235
|
+
exitCode: 1,
|
|
236
|
+
output: "",
|
|
237
|
+
stderr: message,
|
|
238
|
+
usage: emptyUsage(),
|
|
239
|
+
model,
|
|
240
|
+
stopReason: "error",
|
|
241
|
+
errorMessage: message,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
184
244
|
return runSubagentProcess({
|
|
185
245
|
agent: agentName,
|
|
186
246
|
task,
|
|
187
247
|
model,
|
|
188
248
|
bin: codexBin(),
|
|
189
249
|
args,
|
|
250
|
+
env: codexChildEnv(),
|
|
190
251
|
cwd,
|
|
191
252
|
idleTimeoutMs: opts.idleTimeoutMs,
|
|
192
253
|
signal: opts.signal,
|
|
193
254
|
onLive: opts.onLive,
|
|
194
255
|
acc: newCodexAccumulator(model),
|
|
195
256
|
foldLine: foldCodexEventLine,
|
|
257
|
+
requireTerminalEvent: true,
|
|
258
|
+
terminalEventLabel: "Codex turn.completed",
|
|
196
259
|
});
|
|
197
260
|
}
|
|
198
261
|
/**
|
|
@@ -201,5 +264,7 @@ export async function runCodexAgentTask(defaultCwd, agents, agentName, task, opt
|
|
|
201
264
|
*/
|
|
202
265
|
export const codexSubagentRunner = {
|
|
203
266
|
runTask: runCodexAgentTask,
|
|
267
|
+
usageAccounting: "tokens-only",
|
|
204
268
|
};
|
|
269
|
+
runCodexAgentTask.usageAccounting = "tokens-only";
|
|
205
270
|
//# sourceMappingURL=codex-runner.js.map
|
package/dist/codex-runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-runner.js","sourceRoot":"","sources":["../src/codex-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,GAOlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"codex-runner.js","sourceRoot":"","sources":["../src/codex-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN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KAAK,CAAC,CAAC,CAAC;QAC7F,OAAO;YACN,KAAK,EAAE,SAAS;YAChB,IAAI;YACJ,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,OAAO;YACf,KAAK,EAAE,UAAU,EAAE;YACnB,KAAK;YACL,UAAU,EAAE,OAAO;YACnB,YAAY,EAAE,OAAO;SACrB,CAAC;IACH,CAAC;IAED,OAAO,kBAAkB,CAAC;QACzB,KAAK,EAAE,SAAS;QAChB,IAAI;QACJ,KAAK;QACL,GAAG,EAAE,QAAQ,EAAE;QACf,IAAI;QACJ,GAAG,EAAE,aAAa,EAAE;QACpB,GAAG;QACH,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,EAAE,mBAAmB,CAAC,KAAK,CAAC;QAC/B,QAAQ,EAAE,kBAAkB;QAC5B,oBAAoB,EAAE,IAAI;QAC1B,kBAAkB,EAAE,sBAAsB;KAC1C,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC/D,OAAO,EAAE,iBAAiB;IAC1B,eAAe,EAAE,aAAa;CAC9B,CAAC;AAED,iBAAmF,CAAC,eAAe,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grok Build subagent runner — the Grok host's `SubagentRunner` implementation.
|
|
3
|
+
*
|
|
4
|
+
* Spawns an isolated `grok -p --output-format streaming-json` process per task
|
|
5
|
+
* and folds its NDJSON event stream into the same host-neutral `RunResult` the
|
|
6
|
+
* pi/codex/claude/opencode runners produce, so the engine (runtime.ts) treats a
|
|
7
|
+
* Grok subagent identically.
|
|
8
|
+
*
|
|
9
|
+
* Official headless streaming-json schema (docs.x.ai / ~/.grok/docs/user-guide/14-headless-mode.md):
|
|
10
|
+
* {"type":"text","data":"…"} ← response text chunk
|
|
11
|
+
* {"type":"thought","data":"…"} ← reasoning (not answer)
|
|
12
|
+
* {"type":"end","stopReason":"EndTurn","sessionId":"…","requestId":"…"}
|
|
13
|
+
* {"type":"error","message":"…"} ← fatal
|
|
14
|
+
* (also non-exhaustive: max_turns_reached, auto_compact_*, …)
|
|
15
|
+
*
|
|
16
|
+
* Mapping to the host-neutral contract:
|
|
17
|
+
* - output = concatenated `text` event data (final answer)
|
|
18
|
+
* - lastActivity = latest text/thought chunk or end/error summary
|
|
19
|
+
* - usage = zeros today because Grok 0.2.93 streaming-json does not
|
|
20
|
+
* emit token/cost fields. The runner advertises that fact
|
|
21
|
+
* so budgeted MCP runs are rejected instead of silently
|
|
22
|
+
* running without a ceiling.
|
|
23
|
+
* - failure = an `error` event, or a non-zero process exit
|
|
24
|
+
*
|
|
25
|
+
* Permission mapping (codex `sandboxForTools` analogue):
|
|
26
|
+
* - read-only whitelist → an operator-configured custom profile extending
|
|
27
|
+
* `read-only`, a known-good `--tools` allowlist, and mutator deny rules
|
|
28
|
+
* - mutating / no whitelist → an operator-configured custom sandbox plus
|
|
29
|
+
* `--always-approve`. Grok's built-in profiles can warn and continue
|
|
30
|
+
* unsandboxed on unsupported hosts; explicit custom profiles fail closed.
|
|
31
|
+
*
|
|
32
|
+
* Process handling (idle watchdog, abort, signal-kill, stderr cap, sanitize)
|
|
33
|
+
* is delegated to shared `runSubagentProcess` in taskflow-core.
|
|
34
|
+
*
|
|
35
|
+
* @see https://docs.x.ai/build/overview
|
|
36
|
+
* @see ~/.grok/docs/user-guide/14-headless-mode.md
|
|
37
|
+
* @see ~/.grok/docs/user-guide/07-mcp-servers.md
|
|
38
|
+
* @see ~/.grok/docs/user-guide/09-plugins.md
|
|
39
|
+
*/
|
|
40
|
+
import { type AgentConfig, type LiveUpdate, type RunOptions, type RunResult, type SubagentRunner, type UsageStats } from "taskflow-core";
|
|
41
|
+
/** Custom sandbox profile required for mutating Grok phases. Built-in profiles
|
|
42
|
+
* may warn and continue without enforcement when the host cannot apply them;
|
|
43
|
+
* Grok documents explicitly requested custom profiles as fail-closed. */
|
|
44
|
+
export declare const GROK_MUTATING_SANDBOX_PROFILE_ENV = "PI_TASKFLOW_GROK_MUTATING_SANDBOX_PROFILE";
|
|
45
|
+
export declare const GROK_READONLY_SANDBOX_PROFILE_ENV = "PI_TASKFLOW_GROK_READONLY_SANDBOX_PROFILE";
|
|
46
|
+
/** Accumulated state folded from a Grok streaming-json event stream. */
|
|
47
|
+
export interface GrokAccumulator {
|
|
48
|
+
usage: UsageStats;
|
|
49
|
+
model?: string;
|
|
50
|
+
/** Final answer = concatenation of all `text` event `data` chunks. */
|
|
51
|
+
finalText: string;
|
|
52
|
+
lastActivity: string;
|
|
53
|
+
/** Set when the stream reported a fatal `error` event. */
|
|
54
|
+
fatalError?: string;
|
|
55
|
+
/** stopReason from the terminal `end` event, if any. */
|
|
56
|
+
stopReason?: string;
|
|
57
|
+
/** sessionId from the terminal `end` event (useful for resume diagnostics). */
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
terminalSeen?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare function newGrokAccumulator(model?: string): GrokAccumulator;
|
|
62
|
+
/**
|
|
63
|
+
* Fold one Grok streaming-json NDJSON line into the accumulator. Returns a
|
|
64
|
+
* LiveUpdate when the stream produced new activity, else null. Empty/malformed
|
|
65
|
+
* lines are ignored — robust to partial buffers and noise, unit-testable
|
|
66
|
+
* without spawning a process.
|
|
67
|
+
*/
|
|
68
|
+
export declare function foldGrokEventLine(acc: GrokAccumulator, line: string): LiveUpdate | null;
|
|
69
|
+
/** Override the grok binary (tests / unusual installs). */
|
|
70
|
+
export declare function grokBin(): string;
|
|
71
|
+
export declare function grokChildEnv(source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
72
|
+
/**
|
|
73
|
+
* Map a phase's tool whitelist to Grok headless permission flags.
|
|
74
|
+
*
|
|
75
|
+
* - no whitelist / mutating tools → an operator-configured fail-closed custom
|
|
76
|
+
* sandbox plus `--always-approve`
|
|
77
|
+
* - read-only whitelist → a fail-closed custom read-only sandbox plus a narrow
|
|
78
|
+
* allowlist and independent deny rules (still pairs with `--always-approve`
|
|
79
|
+
* so the remaining safe tools never block on confirm)
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveGrokMutatingSandboxProfile(env?: NodeJS.ProcessEnv): string | undefined;
|
|
82
|
+
export declare function resolveGrokReadOnlySandboxProfile(env?: NodeJS.ProcessEnv): string | undefined;
|
|
83
|
+
export declare function permissionArgsForGrokTools(tools: string[] | undefined, mutatingSandboxProfile?: string, readOnlySandboxProfile?: string): string[];
|
|
84
|
+
/** Map Taskflow/Pi thinking levels to Grok's --reasoning-effort contract. */
|
|
85
|
+
export declare function resolveGrokThinking(thinking: string | undefined): string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Resolve a modelRoles/pi model id for `grok -m`, or `undefined` to let Grok
|
|
88
|
+
* use its configured default. Drop pi-provider paths (contain `/` with more
|
|
89
|
+
* than one segment is rare for grok; a single slash may be a custom model id
|
|
90
|
+
* from config.toml `[model.x]`) and unresolved `{{placeholder}}`s.
|
|
91
|
+
*
|
|
92
|
+
* Grok custom models are flat keys in `~/.grok/config.toml` (e.g. `my-model`,
|
|
93
|
+
* `grok-build`); pi-style `provider/model` paths are not valid Grok model ids
|
|
94
|
+
* unless the user defined them literally.
|
|
95
|
+
*/
|
|
96
|
+
export declare function resolveGrokModel(model: string | undefined): string | undefined;
|
|
97
|
+
/** Context for {@link buildGrokArgs} — pure inputs to argv construction. */
|
|
98
|
+
export interface GrokArgsCtx {
|
|
99
|
+
systemPrompt: string;
|
|
100
|
+
task: string;
|
|
101
|
+
/** Already-resolved model (opts.model ?? agent.model). */
|
|
102
|
+
model?: string;
|
|
103
|
+
thinking?: string;
|
|
104
|
+
tools?: string[];
|
|
105
|
+
cwd?: string;
|
|
106
|
+
/** Explicit custom sandbox profile used for mutating/default-capable phases. */
|
|
107
|
+
mutatingSandboxProfile?: string;
|
|
108
|
+
/** Explicit custom sandbox profile used for read-only phases. */
|
|
109
|
+
readOnlySandboxProfile?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build the full `grok -p` argv from a phase's resolved context — PURE
|
|
113
|
+
* (no process.env, no spawn). Extracted so the host's CLI flag contract is
|
|
114
|
+
* unit-testable in CI without a live Grok session.
|
|
115
|
+
*
|
|
116
|
+
* grok -p <task> --output-format streaming-json
|
|
117
|
+
* [--sandbox <custom-mutating> --always-approve |
|
|
118
|
+
* --sandbox <custom-read-only> --tools … --always-approve]
|
|
119
|
+
* [--model m] [--reasoning-effort level] [--cwd dir] [--rules systemPrompt]
|
|
120
|
+
*/
|
|
121
|
+
export declare function buildGrokArgs(ctx: GrokArgsCtx): string[];
|
|
122
|
+
/**
|
|
123
|
+
* Run a single subagent task via `grok -p --output-format streaming-json`.
|
|
124
|
+
* Resolves the agent from `agents` by name; returns the same structured
|
|
125
|
+
* `RunResult` the other host runners do.
|
|
126
|
+
*/
|
|
127
|
+
export declare function runGrokAgentTask(defaultCwd: string, agents: AgentConfig[], agentName: string, task: string, opts: RunOptions, globalThinking?: string): Promise<RunResult>;
|
|
128
|
+
/**
|
|
129
|
+
* The Grok host's `SubagentRunner`. Drops into `RuntimeDeps.runTask` exactly
|
|
130
|
+
* like the other host runners, so the engine runs unchanged on Grok Build.
|
|
131
|
+
*/
|
|
132
|
+
export declare const grokSubagentRunner: SubagentRunner<AgentConfig>;
|
|
133
|
+
//# sourceMappingURL=grok-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-runner.d.ts","sourceRoot":"","sources":["../src/grok-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAIN,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,U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