@claudexor/harness-codex 1.0.1 → 2.1.2

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.
@@ -0,0 +1,4 @@
1
+ import type { HarnessRunSpec } from "@claudexor/schema";
2
+ /** Convert verified image resources to Codex's repeatable file-path arguments. */
3
+ export declare function codexImageArgs(attachments: HarnessRunSpec["attachments"] | undefined): string[];
4
+ //# sourceMappingURL=attachments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../src/attachments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,GAAG,SAAS,GAAG,MAAM,EAAE,CAM/F"}
@@ -0,0 +1,11 @@
1
+ import { readVerifiedAttachmentBytes } from "@claudexor/core";
2
+ /** Convert verified image resources to Codex's repeatable file-path arguments. */
3
+ export function codexImageArgs(attachments) {
4
+ return (attachments ?? []).flatMap((attachment) => {
5
+ if (attachment.kind !== "image")
6
+ return [];
7
+ readVerifiedAttachmentBytes(attachment);
8
+ return ["-i", attachment.path];
9
+ });
10
+ }
11
+ //# sourceMappingURL=attachments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../src/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAG9D,kFAAkF;AAClF,MAAM,UAAU,cAAc,CAAC,WAAsD;IACnF,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAChD,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,CAAC;QAC3C,2BAA2B,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { runCapture } from "@claudexor/core";
2
+ export declare const CODEX_FILE_AUTH_OVERRIDE = "cli_auth_credentials_store=\"file\"";
3
+ export declare const CODEX_FILE_AUTH_ARGS: readonly ["-c", "cli_auth_credentials_store=\"file\""];
4
+ /**
5
+ * Resolve an OpenAI API key for codex from the environment. Claudexor-managed
6
+ * `api_key` auth mirrors the harness's own variable (`OPENAI_API_KEY`); a
7
+ * dedicated `CLAUDEXOR_CODEX_API_KEY` can override it for multi-key setups.
8
+ */
9
+ export declare function codexApiKey(): string | undefined;
10
+ /**
11
+ * Seed `api_key` auth into an isolated CODEX_HOME. Codex does not read
12
+ * `OPENAI_API_KEY` from the environment when run against an empty config dir
13
+ * (it requires `auth.json`), so an envelope-scoped CODEX_HOME would otherwise
14
+ * fail with 401 even though a key is available. We write the same file
15
+ * `codex login --with-api-key` produces. No-op when not isolated (use codex's
16
+ * native auth), when no key is available, or when auth already exists.
17
+ */
18
+ export declare function ensureCodexApiAuth(env?: Record<string, string>, allowApiKey?: boolean, apiKeyOverride?: string | null): void;
19
+ /** Claudexor's independent Codex profile; never the operator's ordinary ~/.codex. */
20
+ export declare function defaultNativeCodexHome(): string;
21
+ export type CodexLoginMethod = "chatgpt" | "api_key" | "access_token" | "logged_out" | "unknown";
22
+ export interface CodexLoginProbe {
23
+ /** True for any typed authenticated status; native readiness additionally requires method=chatgpt. */
24
+ authed: boolean;
25
+ method: CodexLoginMethod;
26
+ probeError: string | null;
27
+ }
28
+ export interface CodexLoginProbeOptions {
29
+ /** Exact environment the eventual Codex child will use. */
30
+ env?: Record<string, string | null | undefined>;
31
+ /** Explicit CODEX_HOME for the probe (INV-135, release wave round-17
32
+ * BLOCK): without it the probe re-normalizes onto the DEFAULT native home —
33
+ * a credential-profile probe must inspect ITS OWN store, never the
34
+ * default's. Callers without a profile omit it and keep the default. */
35
+ codexHome?: string;
36
+ abortSignal?: AbortSignal;
37
+ runCapture?: typeof runCapture;
38
+ }
39
+ /**
40
+ * Native-session probe with a distinct PROBE-FAILURE state. `codex login
41
+ * status` exits non-zero both when logged out AND when the CLI cannot even
42
+ * load `~/.codex/config.toml` (e.g. the config uses a newer option enum than
43
+ * the resolved binary understands — the stale-shim case). Collapsing those
44
+ * into "not logged in" hid a real subscription behind a config error; doctor
45
+ * must fail loudly with the CLI's own message instead.
46
+ */
47
+ export declare function probeLogin(bin?: string, options?: CodexLoginProbeOptions): Promise<CodexLoginProbe>;
48
+ export declare function hasApiKey(): boolean;
49
+ /**
50
+ * Auth route the codex child will ACTUALLY run under, read from the same
51
+ * `auth.json` codex itself loads in a Claudexor-created scoped CODEX_HOME.
52
+ * The vendor-owned native home is deliberately not a fallback and must remain
53
+ * opaque. The file's own `auth_mode` field is the typed source of truth:
54
+ * "chatgpt" = subscription session, "apikey" = API key. Null when the file is
55
+ * absent/unreadable or carries an unknown mode — callers must treat that as
56
+ * undisclosed, never guess.
57
+ */
58
+ export declare function codexAuthModeAt(home: string): "local_session" | "api_key" | null;
59
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7E,eAAO,MAAM,wBAAwB,wCAAsC,CAAC;AAC5E,eAAO,MAAM,oBAAoB,wDAA4C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,MAAM,GAAG,SAAS,CAUhD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,WAAW,UAAO,EAClB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAC7B,IAAI,CAiBN;AAED,qFAAqF;AACrF,wBAAgB,sBAAsB,IAAI,MAAM,CAI/C;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,YAAY,GAAG,SAAS,CAAC;AACjG,MAAM,WAAW,eAAe;IAC9B,sGAAsG;IACtG,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAChD;;;4EAGwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,UAAU,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,GAAE,MAAY,EACjB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC,CAkE1B;AAED,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,GAAG,IAAI,CAYhF"}
package/dist/auth.js ADDED
@@ -0,0 +1,154 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { labelStreams, providerScrubEnv, runCapture } from "@claudexor/core";
4
+ import { resolveSecret } from "@claudexor/secrets";
5
+ import { ensureDir, redactSecrets, userConfigDir } from "@claudexor/util";
6
+ const BIN = process.env.CLAUDEXOR_CODEX_BIN || "codex";
7
+ export const CODEX_FILE_AUTH_OVERRIDE = 'cli_auth_credentials_store="file"';
8
+ export const CODEX_FILE_AUTH_ARGS = ["-c", CODEX_FILE_AUTH_OVERRIDE];
9
+ /**
10
+ * Resolve an OpenAI API key for codex from the environment. Claudexor-managed
11
+ * `api_key` auth mirrors the harness's own variable (`OPENAI_API_KEY`); a
12
+ * dedicated `CLAUDEXOR_CODEX_API_KEY` can override it for multi-key setups.
13
+ */
14
+ export function codexApiKey() {
15
+ // The hermetic kill switch is honored inside resolveSecret (single owner).
16
+ const stored = resolveSecret("openai");
17
+ return (process.env.CLAUDEXOR_CODEX_API_KEY ||
18
+ process.env.CODEX_API_KEY ||
19
+ process.env.OPENAI_API_KEY ||
20
+ stored ||
21
+ undefined);
22
+ }
23
+ /**
24
+ * Seed `api_key` auth into an isolated CODEX_HOME. Codex does not read
25
+ * `OPENAI_API_KEY` from the environment when run against an empty config dir
26
+ * (it requires `auth.json`), so an envelope-scoped CODEX_HOME would otherwise
27
+ * fail with 401 even though a key is available. We write the same file
28
+ * `codex login --with-api-key` produces. No-op when not isolated (use codex's
29
+ * native auth), when no key is available, or when auth already exists.
30
+ */
31
+ export function ensureCodexApiAuth(env, allowApiKey = true, apiKeyOverride) {
32
+ if (!allowApiKey)
33
+ return;
34
+ const home = env?.["CODEX_HOME"];
35
+ if (!home)
36
+ return;
37
+ if (resolve(home) === resolve(defaultNativeCodexHome())) {
38
+ throw new Error("refusing to read or write the vendor-owned native Codex auth store");
39
+ }
40
+ // A profile's namespaced key (INV-135) beats the engine-default slot; the
41
+ // override is exact — a missing profile secret never falls back.
42
+ const apiKey = apiKeyOverride !== undefined ? apiKeyOverride : codexApiKey();
43
+ if (!apiKey)
44
+ return;
45
+ const authPath = join(home, "auth.json");
46
+ if (existsSync(authPath))
47
+ return;
48
+ mkdirSync(home, { recursive: true });
49
+ writeFileSync(authPath, JSON.stringify({ auth_mode: "apikey", OPENAI_API_KEY: apiKey }) + "\n", {
50
+ mode: 0o600,
51
+ });
52
+ }
53
+ /** Claudexor's independent Codex profile; never the operator's ordinary ~/.codex. */
54
+ export function defaultNativeCodexHome() {
55
+ const override = process.env.CLAUDEXOR_CODEX_NATIVE_HOME;
56
+ if (override && override.trim())
57
+ return override;
58
+ return join(userConfigDir(), "native", "codex");
59
+ }
60
+ /**
61
+ * Native-session probe with a distinct PROBE-FAILURE state. `codex login
62
+ * status` exits non-zero both when logged out AND when the CLI cannot even
63
+ * load `~/.codex/config.toml` (e.g. the config uses a newer option enum than
64
+ * the resolved binary understands — the stale-shim case). Collapsing those
65
+ * into "not logged in" hid a real subscription behind a config error; doctor
66
+ * must fail loudly with the CLI's own message instead.
67
+ */
68
+ export async function probeLogin(bin = BIN, options = {}) {
69
+ try {
70
+ const home = options.codexHome ?? defaultNativeCodexHome();
71
+ ensureDir(home);
72
+ const env = {
73
+ ...(options.env ?? {}),
74
+ ...providerScrubEnv(),
75
+ CODEX_HOME: home,
76
+ };
77
+ const r = await (options.runCapture ?? runCapture)(bin, [...CODEX_FILE_AUTH_ARGS, "login", "status"], {
78
+ env,
79
+ timeoutMs: 10_000,
80
+ abortSignal: options.abortSignal,
81
+ cancelSignal: "SIGTERM",
82
+ cancelKillDelayMs: 0,
83
+ });
84
+ const text = `${r.stdout}\n${r.stderr}`;
85
+ const statusLines = text
86
+ .replaceAll("\r", "")
87
+ .split("\n")
88
+ .map((line) => line.trim())
89
+ .filter(Boolean);
90
+ // "Not logged in" is codex's NORMAL logged-out answer (exit 1, no error
91
+ // prefix). Anything else on a failing probe is a probe error, not an auth
92
+ // verdict (adapter-local knowledge of the native CLI's output is allowed).
93
+ if (statusLines.some((line) => /^not logged in[.!]?$/i.test(line))) {
94
+ return { authed: false, method: "logged_out", probeError: null };
95
+ }
96
+ if (r.code === 0 && statusLines.some((line) => /^logged in using chatgpt[.!]?$/i.test(line))) {
97
+ return { authed: true, method: "chatgpt", probeError: null };
98
+ }
99
+ if (r.code === 0 &&
100
+ statusLines.some((line) => /^logged in using (?:an? )?api key[.!]?$/i.test(line))) {
101
+ return { authed: true, method: "api_key", probeError: null };
102
+ }
103
+ if (r.code === 0 &&
104
+ statusLines.some((line) => /^logged in using (?:an? )?access token[.!]?$/i.test(line))) {
105
+ return { authed: true, method: "access_token", probeError: null };
106
+ }
107
+ // Redact BEFORE labelStreams truncates: truncation could split a token
108
+ // into a prefix the redactor no longer recognizes.
109
+ const detail = labelStreams(r.stderr, r.stdout, { transform: redactSecrets });
110
+ const reason = detail ?? `codex login status exited with ${r.code ?? r.signal ?? "unknown result"}`;
111
+ return {
112
+ authed: false,
113
+ method: "unknown",
114
+ probeError: r.code === 0 ? `unrecognized login status: ${reason}` : reason,
115
+ };
116
+ }
117
+ catch (err) {
118
+ return {
119
+ authed: false,
120
+ method: "unknown",
121
+ probeError: [...redactSecrets(err instanceof Error ? err.message : String(err))]
122
+ .slice(0, 300)
123
+ .join(""),
124
+ };
125
+ }
126
+ }
127
+ export function hasApiKey() {
128
+ return Boolean(codexApiKey());
129
+ }
130
+ /**
131
+ * Auth route the codex child will ACTUALLY run under, read from the same
132
+ * `auth.json` codex itself loads in a Claudexor-created scoped CODEX_HOME.
133
+ * The vendor-owned native home is deliberately not a fallback and must remain
134
+ * opaque. The file's own `auth_mode` field is the typed source of truth:
135
+ * "chatgpt" = subscription session, "apikey" = API key. Null when the file is
136
+ * absent/unreadable or carries an unknown mode — callers must treat that as
137
+ * undisclosed, never guess.
138
+ */
139
+ export function codexAuthModeAt(home) {
140
+ if (!home.trim() || resolve(home) === resolve(defaultNativeCodexHome()))
141
+ return null;
142
+ try {
143
+ const parsed = JSON.parse(readFileSync(join(home, "auth.json"), "utf8"));
144
+ if (parsed.auth_mode === "chatgpt")
145
+ return "local_session";
146
+ if (parsed.auth_mode === "apikey")
147
+ return "api_key";
148
+ return null;
149
+ }
150
+ catch {
151
+ return null;
152
+ }
153
+ }
154
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAA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CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,sBAAsB,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IACrF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAEtE,CAAC;QACF,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;YAAE,OAAO,eAAe,CAAC;QAC3D,IAAI,MAAM,CAAC,SAAS,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,28 +1,16 @@
1
1
  import type { HarnessRunSpec } from "@claudexor/schema";
2
2
  import type { HarnessAdapter } from "@claudexor/core";
3
- /**
4
- * Seed `api_key` auth into an isolated CODEX_HOME. Codex does not read
5
- * `OPENAI_API_KEY` from the environment when run against an empty config dir
6
- * (it requires `auth.json`), so an envelope-scoped CODEX_HOME would otherwise
7
- * fail with 401 even though a key is available. We write the same file
8
- * `codex login --with-api-key` produces. No-op when not isolated (use codex's
9
- * native auth), when no key is available, or when auth already exists.
10
- */
11
- export declare function ensureCodexApiAuth(env?: Record<string, string>, allowApiKey?: boolean): void;
12
- /** The user's real codex home (native ChatGPT/subscription session lives here). */
13
- export declare function defaultNativeCodexHome(): string;
14
- /**
15
- * Seed the user's NATIVE codex session (`auth.json`, ChatGPT/subscription mode)
16
- * into an isolated CODEX_HOME so a Max/Pro subscriber with NO API key can run
17
- * inside a Claudexor envelope. This is the "subscription-first must actually
18
- * work" fix: previously the scoped empty CODEX_HOME hid the native session and
19
- * the run failed demanding an API key.
20
- *
21
- * Copies ONLY if the scoped auth is absent and a native `auth.json` exists; never
22
- * overwrites (codex refreshes the token in place). Returns true when scoped auth
23
- * is present afterwards. No-op when not isolated or no native session exists.
24
- */
25
- export declare function ensureCodexNativeAuth(env?: Record<string, string>, nativeHome?: string): boolean;
3
+ import { runCliHarness, selectStrictAuthRoute } from "@claudexor/core";
4
+ import { smokeIsolatedApiKey } from "./smoke.js";
5
+ export { canonicalCodexProfileHome } from "./profile.js";
6
+ export declare const BIN: string;
7
+ /** Exported for focused route-policy tests; runtime uses this exact selector. */
8
+ export declare const selectCodexRunAuthRoute: typeof selectStrictAuthRoute;
9
+ export { CODEX_FILE_AUTH_ARGS, CODEX_FILE_AUTH_OVERRIDE, codexApiKey, codexAuthModeAt, defaultNativeCodexHome, ensureCodexApiAuth, probeLogin, } from "./auth.js";
10
+ import { codexApiKey, hasApiKey, probeLogin } from "./auth.js";
11
+ declare function detectVersion(abortSignal?: AbortSignal): Promise<string | null>;
12
+ export declare function redactCodexDoctorDetail(text: string): string;
13
+ export declare function codexNativeEnv(base?: Record<string, string | null | undefined>, codexHome?: string): Record<string, string | null | undefined>;
26
14
  /**
27
15
  * Inject the Playwright browser MCP as stateless `-c mcp_servers.browser.*`
28
16
  * config overrides (live-verified: codex accepts array-valued `-c` overrides and
@@ -42,11 +30,24 @@ export declare function codexBrowserArgs(browser: HarnessRunSpec["browser"], ext
42
30
  * mcp_servers.node_repl"), which broke every scoped-home / api_key / MCP run.
43
31
  */
44
32
  export declare function codexConfigHasNodeRepl(codexHome: string | null | undefined): boolean;
45
- export declare function codexExecArgs(spec: Pick<HarnessRunSpec, "access" | "model_hint" | "effort_hint" | "external_context_policy" | "prompt" | "attachments" | "browser"> & {
33
+ export declare function codexExecArgs(spec: Pick<HarnessRunSpec, "access" | "model_hint" | "effort_hint" | "external_context_policy" | "prompt" | "instructions" | "attachments" | "browser"> & {
46
34
  resume_session_id?: string | null;
47
35
  }, opts?: {
48
36
  suppressNodeRepl?: boolean;
49
37
  outputSchemaPath?: string | null;
50
38
  }): string[];
51
- export declare function createCodexAdapter(): HarnessAdapter;
39
+ /** The runtime surface the profile module needs (test-stubbable). */
40
+ export type CodexProfileRuntimeDeps = Pick<CodexRuntimeDeps, "probeLogin" | "resolveProfileSecret">;
41
+ type CodexRuntimeDeps = {
42
+ detectVersion: typeof detectVersion;
43
+ probeLogin: typeof probeLogin;
44
+ hasApiKey: typeof hasApiKey;
45
+ codexApiKey: typeof codexApiKey;
46
+ /** Profile-scoped secret resolution (INV-135): reads exactly the profile's
47
+ * namespaced ref, never the engine-default ladder. */
48
+ resolveProfileSecret: (ref: string) => string | null;
49
+ smokeIsolatedApiKey: typeof smokeIsolatedApiKey;
50
+ runCliHarness: typeof runCliHarness;
51
+ };
52
+ export declare function createCodexAdapter(deps?: Partial<CodexRuntimeDeps>): HarnessAdapter;
52
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA+E,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErI,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4BlE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,UAAO,GAAG,IAAI,CAczF;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,IAAI,MAAM,CAI/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,UAAU,GAAE,MAAiC,GAC5C,OAAO,CAmBT;AAuGD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,qBAAqB,CAAC,EAAE,cAAc,CAAC,yBAAyB,CAAC,GAChE,MAAM,EAAE,CAYV;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GA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