@inventarch/cli 0.0.0-stage → 1.0.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 (110) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +19 -2
  4. package/SPEC.md +30 -0
  5. package/assets/base/71f0665cb1ffc3f3964fc7710528451f635d664bdf4b8c95005ee97c21db5928.ia.tgz +0 -0
  6. package/assets/base.json +6 -0
  7. package/assets/host/43a1f8c471141b1f2f46cef4411a9a61c00da1c1aa19d277189ae2423282bfd6.tgz +0 -0
  8. package/assets/host.json +6 -0
  9. package/assets/vocabulary.json +3268 -0
  10. package/dist/args.d.ts +62 -0
  11. package/dist/args.d.ts.map +1 -0
  12. package/dist/args.js +117 -0
  13. package/dist/args.js.map +1 -0
  14. package/dist/briefing.d.ts +76 -0
  15. package/dist/briefing.d.ts.map +1 -0
  16. package/dist/briefing.js +105 -0
  17. package/dist/briefing.js.map +1 -0
  18. package/dist/channel.d.ts +22 -0
  19. package/dist/channel.d.ts.map +1 -0
  20. package/dist/channel.js +74 -0
  21. package/dist/channel.js.map +1 -0
  22. package/dist/claude-cli.d.ts +35 -0
  23. package/dist/claude-cli.d.ts.map +1 -0
  24. package/dist/claude-cli.js +101 -0
  25. package/dist/claude-cli.js.map +1 -0
  26. package/dist/commands.d.ts +39 -0
  27. package/dist/commands.d.ts.map +1 -0
  28. package/dist/commands.js +436 -0
  29. package/dist/commands.js.map +1 -0
  30. package/dist/compile.d.ts +39 -0
  31. package/dist/compile.d.ts.map +1 -0
  32. package/dist/compile.js +136 -0
  33. package/dist/compile.js.map +1 -0
  34. package/dist/consumer.d.ts +137 -0
  35. package/dist/consumer.d.ts.map +1 -0
  36. package/dist/consumer.js +366 -0
  37. package/dist/consumer.js.map +1 -0
  38. package/dist/decline.d.ts +7 -0
  39. package/dist/decline.d.ts.map +1 -0
  40. package/dist/decline.js +78 -0
  41. package/dist/decline.js.map +1 -0
  42. package/dist/distribute.d.ts +163 -0
  43. package/dist/distribute.d.ts.map +1 -0
  44. package/dist/distribute.js +664 -0
  45. package/dist/distribute.js.map +1 -0
  46. package/dist/doctor-user.d.ts +45 -0
  47. package/dist/doctor-user.d.ts.map +1 -0
  48. package/dist/doctor-user.js +193 -0
  49. package/dist/doctor-user.js.map +1 -0
  50. package/dist/doctor.d.ts +57 -0
  51. package/dist/doctor.d.ts.map +1 -0
  52. package/dist/doctor.js +754 -0
  53. package/dist/doctor.js.map +1 -0
  54. package/dist/format.d.ts +25 -0
  55. package/dist/format.d.ts.map +1 -0
  56. package/dist/format.js +168 -0
  57. package/dist/format.js.map +1 -0
  58. package/dist/home-remedy.d.ts +10 -0
  59. package/dist/home-remedy.d.ts.map +1 -0
  60. package/dist/home-remedy.js +26 -0
  61. package/dist/home-remedy.js.map +1 -0
  62. package/dist/host-projection.d.ts +11 -0
  63. package/dist/host-projection.d.ts.map +1 -0
  64. package/dist/host-projection.js +73 -0
  65. package/dist/host-projection.js.map +1 -0
  66. package/dist/host.d.ts +162 -0
  67. package/dist/host.d.ts.map +1 -0
  68. package/dist/host.js +599 -0
  69. package/dist/host.js.map +1 -0
  70. package/dist/init.d.ts +217 -0
  71. package/dist/init.d.ts.map +1 -0
  72. package/dist/init.js +840 -0
  73. package/dist/init.js.map +1 -0
  74. package/dist/inspect.d.ts +32 -0
  75. package/dist/inspect.d.ts.map +1 -0
  76. package/dist/inspect.js +226 -0
  77. package/dist/inspect.js.map +1 -0
  78. package/dist/main.d.ts +24 -0
  79. package/dist/main.d.ts.map +1 -0
  80. package/dist/main.js +215 -0
  81. package/dist/main.js.map +1 -0
  82. package/dist/operation-help.d.ts +14 -0
  83. package/dist/operation-help.d.ts.map +1 -0
  84. package/dist/operation-help.js +75 -0
  85. package/dist/operation-help.js.map +1 -0
  86. package/dist/pack.d.ts +17 -0
  87. package/dist/pack.d.ts.map +1 -0
  88. package/dist/pack.js +121 -0
  89. package/dist/pack.js.map +1 -0
  90. package/dist/render.d.ts +165 -0
  91. package/dist/render.d.ts.map +1 -0
  92. package/dist/render.js +277 -0
  93. package/dist/render.js.map +1 -0
  94. package/dist/session.d.ts +13 -0
  95. package/dist/session.d.ts.map +1 -0
  96. package/dist/session.js +25 -0
  97. package/dist/session.js.map +1 -0
  98. package/dist/user-host.d.ts +59 -0
  99. package/dist/user-host.d.ts.map +1 -0
  100. package/dist/user-host.js +228 -0
  101. package/dist/user-host.js.map +1 -0
  102. package/dist/validate.d.ts +53 -0
  103. package/dist/validate.d.ts.map +1 -0
  104. package/dist/validate.js +220 -0
  105. package/dist/validate.js.map +1 -0
  106. package/dist/vocabulary.d.ts +55 -0
  107. package/dist/vocabulary.d.ts.map +1 -0
  108. package/dist/vocabulary.js +179 -0
  109. package/dist/vocabulary.js.map +1 -0
  110. package/package.json +153 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAClD,KAAK,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7C,eAAO,MAAM,WAAW,2BAA2B,CAAC;AACpD,eAAO,MAAM,QAAQ,mBAAmB,CAAC;AAEzC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AACD,MAAM,WAAW,gBAA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Determinism is a requirement on this writer, not a hope: records
5
+ * are sorted by canonical identity, diagnostics by (path, line, code, message), object keys are emitted sorted and
6
+ * the document ends in exactly one newline — which is what the distribution's own `json()` serializer does, so it
7
+ * is the function called rather than a second encoder beside it.
8
+ *
9
+ * No product-quality claim. Compilation establishes that records parse, that references resolve and that declared
10
+ * structural obligations are satisfied. Where a semantic evaluator is unavailable the compiler carries
11
+ * IA-COMP-NOT-EVALUATED through into `diagnostics` and `counts.notEvaluated`; that result is never rolled into a
12
+ * pass, never suppressed and never omitted from --json.
13
+ */
14
+ import { resolve } from 'node:path';
15
+ import { createFile, json, LANGUAGE_IDENTITY, replace, sha256, workOutputPath, } from '@inventarch/distribution/services';
16
+ import { Refusal, requireRoot } from './consumer.js';
17
+ import { codeOf, openSession } from './session.js';
18
+ import { NOT_EVALUATED } from './validate.js';
19
+ import { atom, document, entry, headerLine, sectionLabel, truncateDigest, words } from './render.js';
20
+ export const DEFAULT_OUT = '.ia/work/compiled.json';
21
+ export const ARTIFACT = 'ia.compiled.v1';
22
+ const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
23
+ /** The ordering the compliance layer already applies, reused rather than reinvented. */
24
+ const orderFindings = (findings) => [...findings].sort((a, b) => compare(a.path, b.path) || a.line - b.line || compare(a.code, b.code) || compare(a.message, b.message));
25
+ export function buildArtifact(root, session) {
26
+ const admission = session.admission();
27
+ const records = [...session.reader.records()].sort((a, b) => compare(a.identity, b.identity));
28
+ const diagnostics = orderFindings(admission.findings);
29
+ const artifact = {
30
+ formatVersion: 1,
31
+ artifact: ARTIFACT,
32
+ language: LANGUAGE_IDENTITY.language,
33
+ kernelDigest: LANGUAGE_IDENTITY.kernelDigest,
34
+ root,
35
+ revision: admission.revision,
36
+ records,
37
+ diagnostics,
38
+ counts: {
39
+ records: records.length,
40
+ errors: diagnostics.filter((finding) => finding.severity === 'error').length,
41
+ warnings: diagnostics.filter((finding) => finding.severity === 'warning').length,
42
+ notEvaluated: diagnostics.filter((finding) => NOT_EVALUATED.has(finding.code)).length,
43
+ },
44
+ };
45
+ const text = json(artifact);
46
+ return { artifact, text, digest: sha256(text) };
47
+ }
48
+ export function collectCompile(root) {
49
+ const session = openSession(root);
50
+ try {
51
+ return buildArtifact(root, session);
52
+ }
53
+ finally {
54
+ session.close();
55
+ }
56
+ }
57
+ /** §2.4: the artifact is written even when the compilation produced errors; the exit class carries the verdict. */
58
+ export const compileExit = (view) => (view.artifact.counts.errors === 0 ? 0 : 1);
59
+ export function compileEnvelope(view, path) {
60
+ return {
61
+ version: 1,
62
+ artifact: path,
63
+ revision: view.artifact.revision,
64
+ digest: view.digest,
65
+ counts: view.artifact.counts,
66
+ };
67
+ }
68
+ export function renderCompile(view, path, caps) {
69
+ const counts = view.artifact.counts;
70
+ const facts = [
71
+ words(`${counts.records} records, ${counts.errors} errors, ${counts.warnings} warnings, ${counts.notEvaluated} not evaluated.`),
72
+ ];
73
+ if (counts.notEvaluated > 0)
74
+ facts.push(words(`${counts.notEvaluated} checks had no evaluator, so this artifact records a not-evaluated result rather than a pass.`));
75
+ facts.push(words('Compilation establishes that records parse, that references resolve and that declared structural obligations are satisfied. It is not a claim that a design is good.'));
76
+ return document([
77
+ headerLine('Compile', ARTIFACT, [{ text: `revision ${truncateDigest(view.artifact.revision, caps.ascii)}`, column: 50 }], caps),
78
+ entry(facts, { depth: 1, symbol: counts.errors === 0 ? 'success' : 'error' }, caps),
79
+ [
80
+ sectionLabel('Artifact', caps),
81
+ ...entry([
82
+ [atom(path, 'cyan', 0)],
83
+ [
84
+ atom(`sha256 ${truncateDigest(view.digest, caps.ascii)}`, null, 0),
85
+ ...words(`${Buffer.byteLength(view.text)} bytes`, 'dim', 2),
86
+ ],
87
+ ], { depth: 1, symbol: 'info' }, caps),
88
+ ],
89
+ entry([
90
+ words(counts.errors > 0
91
+ ? 'Run "ia validate" for the located findings, fix them, then compile again.'
92
+ : 'Compare two artifacts byte for byte: identical sources on one language version compile identically.'),
93
+ ], { depth: 0, symbol: 'step' }, caps),
94
+ ], { leadingBlank: true });
95
+ }
96
+ /**
97
+ * §2.4: running `ia compile` twice is the ordinary case, so refusing by default is stated rather than discovered.
98
+ * `createFile` raises IA-DIST-LOCAL-MODIFICATION on an existing entry; the code is carried through unchanged and
99
+ * only the next action is added, because a refusal whose remedy is one flag must name that flag.
100
+ */
101
+ function publish(root, path, content, force) {
102
+ if (force) {
103
+ replace(root, path, content);
104
+ return;
105
+ }
106
+ try {
107
+ createFile(root, path, content);
108
+ }
109
+ catch (error) {
110
+ if (codeOf(error, '') !== 'IA-DIST-LOCAL-MODIFICATION')
111
+ throw error;
112
+ throw new Refusal('IA-DIST-LOCAL-MODIFICATION', `${path} already exists`, 3, { path }, 'Pass --force to overwrite it, or choose another --out under .ia/work/.');
113
+ }
114
+ }
115
+ export function runCompile(context) {
116
+ const { args, caps, json: machine } = context;
117
+ const root = requireRoot(context);
118
+ // Placement is decided before the workspace is read, so an unsafe --out never costs a compilation.
119
+ const path = args.flag('stdout')
120
+ ? null
121
+ : workOutputPath({
122
+ root,
123
+ path: args.value('out') ?? DEFAULT_OUT,
124
+ refusal: 'A compiled artifact is written under .ia/work/',
125
+ });
126
+ const view = collectCompile(root);
127
+ const exitCode = compileExit(view);
128
+ // §2.4: with --stdout the artifact is the single value on stdout, so nothing else may be written there.
129
+ if (path === null)
130
+ return { exitCode, stdout: view.text, stderr: '' };
131
+ publish(root, path, Buffer.from(view.text, 'utf8'), args.flag('force'));
132
+ return machine
133
+ ? { exitCode, stdout: JSON.stringify(compileEnvelope(view, resolve(root, path))) + '\n', stderr: '' }
134
+ : { exitCode, stdout: renderCompile(view, path, caps), stderr: '' };
135
+ }
136
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,UAAU,E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AAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACrG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,137 @@
1
+ import type { Arguments } from './args.js';
2
+ import type { CommandSpec } from './commands.js';
3
+ import type { Capabilities, Terminal } from './render.js';
4
+ /**
5
+ * §2.8 rule 3's one question, described rather than performed — the same move `render.ts` makes for the terminal.
6
+ * The reader and the writer arrive from the entry point, so the decision is a pure function of a string and a test
7
+ * observes the exact bytes the question put on the wire. Unlike a rendered result this cannot be returned as text:
8
+ * the prompt has to be written before the answer can be read.
9
+ */
10
+ export interface Interaction {
11
+ /** §2.8 rule 3: both stdin and stdout are terminals. A question that cannot be answered is never asked. */
12
+ readonly interactive: boolean;
13
+ /** §5 keeps every prompt off stdout, so the entry point points this at stderr. */
14
+ readonly write: (text: string) => void;
15
+ /** One line of input, or null at EOF, on a closed stdin, or where stdin cannot be read at all. */
16
+ readonly read: () => Promise<string | null>;
17
+ }
18
+ /** §2.8 rule 3: `y` or `yes`, in any case and ignoring surrounding space. Everything else, EOF included, declines. */
19
+ export declare const consents: (answer: string | null) => boolean;
20
+ /**
21
+ * Shows the change summary, asks once, and reports the answer. What a declined answer means belongs to the caller:
22
+ * §2.8 rule 3 makes declining an answer to the question, not a failure of the command.
23
+ */
24
+ export declare function confirm(interaction: Interaction, summary: string, question: string): Promise<boolean>;
25
+ export interface Host {
26
+ readonly cwd: string;
27
+ readonly env: Readonly<Record<string, string | undefined>>;
28
+ readonly stdout: Terminal;
29
+ readonly stderr: Terminal;
30
+ /** §2.8 rule 3: `--apply` may prompt only when a question can actually be asked and answered. */
31
+ readonly interaction: Interaction;
32
+ readonly version: string;
33
+ /** The directory holding `assets/`, so §2.2's catalogue travels with the package rather than the workspace. */
34
+ readonly packageRoot: string;
35
+ readonly signal?: AbortSignal;
36
+ /**
37
+ * Called once, only when §1.2 step 5 has selected a consumer verb. §3 forbids a SIGINT handler on the legacy
38
+ * route's path, so the entry point installs its cleanup here rather than at startup.
39
+ */
40
+ readonly onConsumerRoute?: () => void | (() => void);
41
+ }
42
+ export interface Result {
43
+ readonly exitCode: number;
44
+ readonly stdout: string;
45
+ readonly stderr: string;
46
+ }
47
+ export interface Context {
48
+ readonly host: Host;
49
+ readonly command: CommandSpec;
50
+ readonly args: Arguments;
51
+ readonly caps: Capabilities;
52
+ readonly json: boolean;
53
+ }
54
+ /** §4: a refusal carries the service's own code unchanged, its exit class, and where it happened. */
55
+ export declare class Refusal extends Error {
56
+ readonly code: string;
57
+ readonly exit: number;
58
+ readonly where: {
59
+ readonly path?: string;
60
+ readonly line?: number;
61
+ readonly identity?: string;
62
+ } | null;
63
+ readonly next: string | null;
64
+ /** §6.5 element 1 when there is no `where`: the invocation that was refused, rendered but never serialized. */
65
+ readonly at: string | null;
66
+ constructor(code: string, message: string, exit: number, where?: {
67
+ readonly path?: string;
68
+ readonly line?: number;
69
+ readonly identity?: string;
70
+ } | null, next?: string | null,
71
+ /** §6.5 element 1 when there is no `where`: the invocation that was refused, rendered but never serialized. */
72
+ at?: string | null);
73
+ }
74
+ /**
75
+ * §5's first signal, raised by a verb that had already written when it observed the signal. The JSON result stays
76
+ * §5's fixed object; the one stderr line gains the rerun that finishes the work, which M5.2 §5 requires `ia init`
77
+ * to name once it has written anything.
78
+ */
79
+ export declare class Interrupted extends Error {
80
+ readonly next: string;
81
+ constructor(next: string);
82
+ }
83
+ /**
84
+ * §4.1: the consumer never rewrites a service's code. Class 4 is unreachable from the three verbs this release
85
+ * implements, because none of them acquires anything over a network, so every unmapped failure is class 3.
86
+ */
87
+ export declare function refusalOf(error: unknown): Refusal;
88
+ /** §4.3 and §6.5. Human mode renders the block on stderr; `--json` emits the one object on stdout. */
89
+ export declare function renderRefusal(refusal: Refusal, caps: Capabilities, json: boolean): Result;
90
+ /** §6.5's strip rule applied to the serializer as well as the renderer, so both carry the same message. */
91
+ export declare const stripFor: (message: string, code: string, location: string | null, identity: string | null) => string;
92
+ export declare const optionLabel: (name: string, short: string | undefined, placeholder: string | undefined) => string;
93
+ export interface Namespace {
94
+ readonly token: string;
95
+ readonly summary: string;
96
+ }
97
+ /**
98
+ * §1.2 step 1 and §7.1. The nine legacy operations are listed verbatim under their own heading, together with
99
+ * their own usage line, because the consumer help is the only place a reader learns that the machine protocol
100
+ * exists and is unchanged. One row points at each operation's own help (spec-0012 CLI-04). Private namespaces are
101
+ * supplied by the caller so that a tree without them prints a help text that does not mention them.
102
+ */
103
+ export declare function renderHelp(host: Host, caps: Capabilities, namespaces: readonly Namespace[]): string;
104
+ export declare function renderCommandHelp(command: CommandSpec, caps: Capabilities): string;
105
+ /**
106
+ * §2.0: walk from cwd toward the filesystem root and take the first directory containing `.ia/src`. Host plugin
107
+ * distribution spec §3: a directory whose `.ia` is the IA home is never a workspace, even if src/ appeared there.
108
+ */
109
+ export declare function discoverRoot(start: string, iaHome?: string): string | undefined;
110
+ /** The IA home for discovery, or undefined when its variable is malformed; the verb that needs the home refuses then. */
111
+ export declare function iaHomeOf(env: Readonly<Record<string, string | undefined>>, home?: string): string | undefined;
112
+ /**
113
+ * §2.0: the real path of the resolved absolute root, because `workspace()` refuses a relative root and any link on the
114
+ * way to one (`apps/distribution/src/files.ts:51`). A failed discovery is exit 3 with IA-DB-ROOT-INVALID.
115
+ */
116
+ export declare function requireRoot(context: Context): string;
117
+ export declare const HELP_TOKENS: ReadonlySet<string>;
118
+ /** §1.2 step 5. Parse, then run; every class-2 check has already happened when a handler is entered. */
119
+ export declare function runCommand(command: CommandSpec, argv: readonly string[], host: Host): Promise<Result>;
120
+ export interface Extension extends Namespace {
121
+ readonly run: (args: readonly string[]) => Promise<{
122
+ readonly exitCode: number;
123
+ readonly stdout: string;
124
+ }>;
125
+ }
126
+ export interface Legacy {
127
+ (args: readonly string[]): {
128
+ readonly exitCode: number;
129
+ readonly stdout: string;
130
+ };
131
+ }
132
+ /**
133
+ * §1.2's ordered table. The first match wins and the order is normative: step 4 precedes step 5 unconditionally,
134
+ * so a legacy operation can never be shadowed by a consumer verb.
135
+ */
136
+ export declare function dispatch(argv: readonly string[], host: Host, legacy: Legacy, extensions: readonly Extension[]): Promise<Result>;
137
+ //# sourceMappingURL=consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../src/consumer.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,WAAW,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,eAAe,CAAC;AAoBxD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAS,MAAM,aAAa,CAAC;AAGjE;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,2GAA2G;IAC3G,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,kGAAkG;IAClG,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC7C;AACD,sHAAsH;AACtH,eAAO,MAAM,QAAQ,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,OACsB,CAAC;AACxE;;;GAGG;AACH,wBAAsB,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAI3G;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,S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