@mainwp/control 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.
- package/LICENSE +674 -0
- package/README.md +583 -0
- package/bin/_exit.js +12 -0
- package/bin/dev.js +7 -0
- package/bin/run.js +7 -0
- package/dist/chat/chat-engine.d.ts +213 -0
- package/dist/chat/chat-engine.d.ts.map +1 -0
- package/dist/chat/chat-engine.js +636 -0
- package/dist/chat/chat-engine.js.map +1 -0
- package/dist/chat/index.d.ts +10 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +14 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/providers/anthropic.d.ts +52 -0
- package/dist/chat/providers/anthropic.d.ts.map +1 -0
- package/dist/chat/providers/anthropic.js +292 -0
- package/dist/chat/providers/anthropic.js.map +1 -0
- package/dist/chat/providers/gemini.d.ts +52 -0
- package/dist/chat/providers/gemini.d.ts.map +1 -0
- package/dist/chat/providers/gemini.js +284 -0
- package/dist/chat/providers/gemini.js.map +1 -0
- package/dist/chat/providers/index.d.ts +19 -0
- package/dist/chat/providers/index.d.ts.map +1 -0
- package/dist/chat/providers/index.js +23 -0
- package/dist/chat/providers/index.js.map +1 -0
- package/dist/chat/providers/local.d.ts +37 -0
- package/dist/chat/providers/local.d.ts.map +1 -0
- package/dist/chat/providers/local.js +130 -0
- package/dist/chat/providers/local.js.map +1 -0
- package/dist/chat/providers/openai-compatible.d.ts +155 -0
- package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
- package/dist/chat/providers/openai-compatible.js +264 -0
- package/dist/chat/providers/openai-compatible.js.map +1 -0
- package/dist/chat/providers/openai.d.ts +24 -0
- package/dist/chat/providers/openai.d.ts.map +1 -0
- package/dist/chat/providers/openai.js +62 -0
- package/dist/chat/providers/openai.js.map +1 -0
- package/dist/chat/providers/openrouter.d.ts +26 -0
- package/dist/chat/providers/openrouter.d.ts.map +1 -0
- package/dist/chat/providers/openrouter.js +65 -0
- package/dist/chat/providers/openrouter.js.map +1 -0
- package/dist/chat/providers/provider-fetch.d.ts +15 -0
- package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
- package/dist/chat/providers/provider-fetch.js +35 -0
- package/dist/chat/providers/provider-fetch.js.map +1 -0
- package/dist/chat/providers/provider.d.ts +214 -0
- package/dist/chat/providers/provider.d.ts.map +1 -0
- package/dist/chat/providers/provider.js +166 -0
- package/dist/chat/providers/provider.js.map +1 -0
- package/dist/chat/providers/sse-reader.d.ts +21 -0
- package/dist/chat/providers/sse-reader.d.ts.map +1 -0
- package/dist/chat/providers/sse-reader.js +48 -0
- package/dist/chat/providers/sse-reader.js.map +1 -0
- package/dist/chat/system-prompt.d.ts +33 -0
- package/dist/chat/system-prompt.d.ts.map +1 -0
- package/dist/chat/system-prompt.js +166 -0
- package/dist/chat/system-prompt.js.map +1 -0
- package/dist/chat/tool-envelope.d.ts +72 -0
- package/dist/chat/tool-envelope.d.ts.map +1 -0
- package/dist/chat/tool-envelope.js +263 -0
- package/dist/chat/tool-envelope.js.map +1 -0
- package/dist/commands/abilities/info.d.ts +21 -0
- package/dist/commands/abilities/info.d.ts.map +1 -0
- package/dist/commands/abilities/info.js +80 -0
- package/dist/commands/abilities/info.js.map +1 -0
- package/dist/commands/abilities/list.d.ts +19 -0
- package/dist/commands/abilities/list.d.ts.map +1 -0
- package/dist/commands/abilities/list.js +98 -0
- package/dist/commands/abilities/list.js.map +1 -0
- package/dist/commands/abilities/run.d.ts +75 -0
- package/dist/commands/abilities/run.d.ts.map +1 -0
- package/dist/commands/abilities/run.js +468 -0
- package/dist/commands/abilities/run.js.map +1 -0
- package/dist/commands/chat.d.ts +54 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +384 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config/show.d.ts +54 -0
- package/dist/commands/config/show.d.ts.map +1 -0
- package/dist/commands/config/show.js +324 -0
- package/dist/commands/config/show.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +412 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/jobs/watch.d.ts +50 -0
- package/dist/commands/jobs/watch.d.ts.map +1 -0
- package/dist/commands/jobs/watch.js +269 -0
- package/dist/commands/jobs/watch.js.map +1 -0
- package/dist/commands/login.d.ts +25 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +165 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/profile/delete.d.ts +22 -0
- package/dist/commands/profile/delete.d.ts.map +1 -0
- package/dist/commands/profile/delete.js +57 -0
- package/dist/commands/profile/delete.js.map +1 -0
- package/dist/commands/profile/list.d.ts +19 -0
- package/dist/commands/profile/list.d.ts.map +1 -0
- package/dist/commands/profile/list.js +53 -0
- package/dist/commands/profile/list.js.map +1 -0
- package/dist/commands/profile/use.d.ts +22 -0
- package/dist/commands/profile/use.d.ts.map +1 -0
- package/dist/commands/profile/use.js +46 -0
- package/dist/commands/profile/use.js.map +1 -0
- package/dist/config/fs-utils.d.ts +14 -0
- package/dist/config/fs-utils.d.ts.map +1 -0
- package/dist/config/fs-utils.js +31 -0
- package/dist/config/fs-utils.js.map +1 -0
- package/dist/config/keychain.d.ts +53 -0
- package/dist/config/keychain.d.ts.map +1 -0
- package/dist/config/keychain.js +175 -0
- package/dist/config/keychain.js.map +1 -0
- package/dist/config/profile-store.d.ts +85 -0
- package/dist/config/profile-store.d.ts.map +1 -0
- package/dist/config/profile-store.js +228 -0
- package/dist/config/profile-store.js.map +1 -0
- package/dist/config/settings.d.ts +71 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +151 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/abilities-executor.d.ts +126 -0
- package/dist/core/abilities-executor.d.ts.map +1 -0
- package/dist/core/abilities-executor.js +264 -0
- package/dist/core/abilities-executor.js.map +1 -0
- package/dist/core/batch-manager.d.ts +113 -0
- package/dist/core/batch-manager.d.ts.map +1 -0
- package/dist/core/batch-manager.js +244 -0
- package/dist/core/batch-manager.js.map +1 -0
- package/dist/core/http-client.d.ts +111 -0
- package/dist/core/http-client.d.ts.map +1 -0
- package/dist/core/http-client.js +329 -0
- package/dist/core/http-client.js.map +1 -0
- package/dist/core/safety-controller.d.ts +114 -0
- package/dist/core/safety-controller.d.ts.map +1 -0
- package/dist/core/safety-controller.js +229 -0
- package/dist/core/safety-controller.js.map +1 -0
- package/dist/hooks/command-not-found.d.ts +12 -0
- package/dist/hooks/command-not-found.d.ts.map +1 -0
- package/dist/hooks/command-not-found.js +58 -0
- package/dist/hooks/command-not-found.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-command.d.ts +123 -0
- package/dist/lib/base-command.d.ts.map +1 -0
- package/dist/lib/base-command.js +285 -0
- package/dist/lib/base-command.js.map +1 -0
- package/dist/output/formatter.d.ts +48 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +138 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json-envelope.d.ts +43 -0
- package/dist/output/json-envelope.d.ts.map +1 -0
- package/dist/output/json-envelope.js +73 -0
- package/dist/output/json-envelope.js.map +1 -0
- package/dist/utils/audit-logger.d.ts +97 -0
- package/dist/utils/audit-logger.d.ts.map +1 -0
- package/dist/utils/audit-logger.js +169 -0
- package/dist/utils/audit-logger.js.map +1 -0
- package/dist/utils/colors.d.ts +29 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/colors.js +36 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/errors.d.ts +107 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +149 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +21 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +20 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/format.d.ts +64 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +69 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/prompt.d.ts +34 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +132 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/retry.d.ts +59 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +96 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/terminal-sanitizer.d.ts +60 -0
- package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
- package/dist/utils/terminal-sanitizer.js +166 -0
- package/dist/utils/terminal-sanitizer.js.map +1 -0
- package/dist/validation/input-sanitizer.d.ts +76 -0
- package/dist/validation/input-sanitizer.d.ts.map +1 -0
- package/dist/validation/input-sanitizer.js +199 -0
- package/dist/validation/input-sanitizer.js.map +1 -0
- package/dist/validation/schema-validator.d.ts +75 -0
- package/dist/validation/schema-validator.d.ts.map +1 -0
- package/dist/validation/schema-validator.js +147 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/oclif.manifest.json +857 -0
- package/package.json +101 -0
- package/scripts/completions/README.md +221 -0
- package/scripts/completions/mainwpcontrol.bash +193 -0
- package/scripts/completions/mainwpcontrol.zsh +267 -0
- package/scripts/completions/profile-completer.sh +35 -0
- package/scripts/completions/regenerate.sh +78 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base command for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all CLI commands:
|
|
5
|
+
* - Profile and authentication management
|
|
6
|
+
* - JSON/human output handling
|
|
7
|
+
* - AbilitiesExecutor initialization
|
|
8
|
+
*/
|
|
9
|
+
import { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { getProfileStore } from '../config/profile-store.js';
|
|
11
|
+
import { getKeychain } from '../config/keychain.js';
|
|
12
|
+
import { loadSettings, resolveSettings, } from '../config/settings.js';
|
|
13
|
+
import { createAbilitiesExecutor } from '../core/abilities-executor.js';
|
|
14
|
+
import { createBatchManager } from '../core/batch-manager.js';
|
|
15
|
+
import { isMainWPCTLError, ConfigError } from '../utils/errors.js';
|
|
16
|
+
import { successOutput, errorOutput } from '../output/json-envelope.js';
|
|
17
|
+
import { ExitCode } from '../utils/exit-codes.js';
|
|
18
|
+
import { formatError, formatWarning } from '../output/formatter.js';
|
|
19
|
+
/**
|
|
20
|
+
* Common flags available to all commands
|
|
21
|
+
*/
|
|
22
|
+
export const commonFlags = {
|
|
23
|
+
json: Flags.boolean({
|
|
24
|
+
description: 'Output JSON (for scripting/CI)',
|
|
25
|
+
// No default - allows distinguishing "not provided" from "explicitly false"
|
|
26
|
+
// Precedence: --json flag > settings.defaultJsonOutput > false
|
|
27
|
+
}),
|
|
28
|
+
quiet: Flags.boolean({
|
|
29
|
+
char: 'q',
|
|
30
|
+
description: 'Suppress output (exit code only)',
|
|
31
|
+
default: false,
|
|
32
|
+
}),
|
|
33
|
+
profile: Flags.string({
|
|
34
|
+
char: 'p',
|
|
35
|
+
description: 'Use a specific profile',
|
|
36
|
+
}),
|
|
37
|
+
debug: Flags.boolean({
|
|
38
|
+
description: 'Show debug output',
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Base command class
|
|
43
|
+
*
|
|
44
|
+
* All mainwpcontrol commands should extend this class.
|
|
45
|
+
*/
|
|
46
|
+
export class BaseCommand extends Command {
|
|
47
|
+
/**
|
|
48
|
+
* Current active profile
|
|
49
|
+
*/
|
|
50
|
+
currentProfile;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to output JSON
|
|
53
|
+
*/
|
|
54
|
+
jsonOutput = false;
|
|
55
|
+
/**
|
|
56
|
+
* Debug mode flag
|
|
57
|
+
*/
|
|
58
|
+
debugMode = false;
|
|
59
|
+
/**
|
|
60
|
+
* Whether debug was explicitly requested on the CLI.
|
|
61
|
+
*/
|
|
62
|
+
explicitDebugMode = false;
|
|
63
|
+
/**
|
|
64
|
+
* Quiet mode flag — suppress stdout output (exit code only)
|
|
65
|
+
*/
|
|
66
|
+
quietMode = false;
|
|
67
|
+
/**
|
|
68
|
+
* Raw settings from settings.json
|
|
69
|
+
*/
|
|
70
|
+
rawSettings = {};
|
|
71
|
+
/**
|
|
72
|
+
* Validated and normalized settings
|
|
73
|
+
*/
|
|
74
|
+
settings = {
|
|
75
|
+
defaultJsonOutput: false,
|
|
76
|
+
timeout: 30000,
|
|
77
|
+
skipSSLVerification: false,
|
|
78
|
+
debug: false,
|
|
79
|
+
chatContextMessages: 20,
|
|
80
|
+
allowInsecureHttp: false,
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Cached executor instance
|
|
84
|
+
*/
|
|
85
|
+
executor;
|
|
86
|
+
/**
|
|
87
|
+
* Cached batch manager instance
|
|
88
|
+
*/
|
|
89
|
+
batchManagerInstance;
|
|
90
|
+
/**
|
|
91
|
+
* Whether this command needs a profile to be loaded.
|
|
92
|
+
* Override to return false for commands like `login` that don't need a profile.
|
|
93
|
+
*/
|
|
94
|
+
needsProfile() {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Initialize common functionality.
|
|
99
|
+
* Call this at the start of each command's run() method.
|
|
100
|
+
*/
|
|
101
|
+
async initCommon(flags) {
|
|
102
|
+
// Load and validate settings
|
|
103
|
+
this.rawSettings = await loadSettings();
|
|
104
|
+
const resolved = resolveSettings(this.rawSettings);
|
|
105
|
+
this.settings = resolved.settings;
|
|
106
|
+
// Apply precedence: explicit flag > settings file > default (false)
|
|
107
|
+
// flags.json is undefined if not provided, boolean if provided
|
|
108
|
+
this.jsonOutput = flags.json ?? this.settings.defaultJsonOutput;
|
|
109
|
+
this.explicitDebugMode = flags.debug === true;
|
|
110
|
+
this.debugMode = flags.debug ?? this.settings.debug;
|
|
111
|
+
// Quiet mode: suppress stdout. --json and explicit --debug override --quiet.
|
|
112
|
+
this.quietMode = (flags.quiet ?? false) && !this.jsonOutput && !this.explicitDebugMode;
|
|
113
|
+
for (const warning of resolved.warnings) {
|
|
114
|
+
this.logToStderr(formatWarning(warning));
|
|
115
|
+
}
|
|
116
|
+
if (this.needsProfile()) {
|
|
117
|
+
await this.loadProfile(flags.profile);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Load the specified or active profile
|
|
122
|
+
*/
|
|
123
|
+
async loadProfile(profileName) {
|
|
124
|
+
const profileStore = getProfileStore();
|
|
125
|
+
if (profileName) {
|
|
126
|
+
const profile = await profileStore.get(profileName);
|
|
127
|
+
if (!profile) {
|
|
128
|
+
throw new ConfigError(`Profile not found: ${profileName}`, undefined, 'List available profiles with `mainwpcontrol profile list` or create one with `mainwpcontrol login`');
|
|
129
|
+
}
|
|
130
|
+
this.currentProfile = profile;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.currentProfile = await profileStore.getActive();
|
|
134
|
+
if (!this.currentProfile) {
|
|
135
|
+
throw new ConfigError('No profile configured.', undefined, 'Create your first profile with `mainwpcontrol login`');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (this.currentProfile) {
|
|
139
|
+
this.debugLog('Loaded profile', {
|
|
140
|
+
profile: this.currentProfile.name,
|
|
141
|
+
dashboardUrl: this.currentProfile.dashboardUrl,
|
|
142
|
+
skipSSLVerification: this.getTransportConfig().skipSSLVerification,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get the AbilitiesExecutor instance
|
|
148
|
+
*/
|
|
149
|
+
async getExecutor() {
|
|
150
|
+
if (this.executor) {
|
|
151
|
+
return this.executor;
|
|
152
|
+
}
|
|
153
|
+
if (!this.currentProfile) {
|
|
154
|
+
throw new ConfigError('No profile loaded', undefined, 'This is an internal error. Please report this issue.');
|
|
155
|
+
}
|
|
156
|
+
const keychain = getKeychain();
|
|
157
|
+
const password = await keychain.getOrThrow(this.currentProfile.name);
|
|
158
|
+
this.executor = createAbilitiesExecutor({
|
|
159
|
+
baseUrl: this.currentProfile.dashboardUrl,
|
|
160
|
+
username: this.currentProfile.username,
|
|
161
|
+
appPassword: password,
|
|
162
|
+
...this.getTransportConfig(),
|
|
163
|
+
});
|
|
164
|
+
this.debugLog('Initialized abilities executor', {
|
|
165
|
+
profile: this.currentProfile.name,
|
|
166
|
+
timeoutMs: this.settings.timeout,
|
|
167
|
+
allowInsecureHttp: this.settings.allowInsecureHttp,
|
|
168
|
+
skipSSLVerification: this.getTransportConfig().skipSSLVerification,
|
|
169
|
+
});
|
|
170
|
+
return this.executor;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get the BatchManager instance (lazy, cached)
|
|
174
|
+
*/
|
|
175
|
+
async getBatchManager() {
|
|
176
|
+
if (this.batchManagerInstance) {
|
|
177
|
+
return this.batchManagerInstance;
|
|
178
|
+
}
|
|
179
|
+
if (!this.currentProfile) {
|
|
180
|
+
throw new ConfigError('No profile loaded', undefined, 'This is an internal error. Please report this issue.');
|
|
181
|
+
}
|
|
182
|
+
const keychain = getKeychain();
|
|
183
|
+
const appPassword = await keychain.getOrThrow(this.currentProfile.name);
|
|
184
|
+
this.batchManagerInstance = createBatchManager({
|
|
185
|
+
baseUrl: this.currentProfile.dashboardUrl,
|
|
186
|
+
username: this.currentProfile.username,
|
|
187
|
+
appPassword,
|
|
188
|
+
...this.getTransportConfig(),
|
|
189
|
+
});
|
|
190
|
+
this.debugLog('Initialized batch manager', {
|
|
191
|
+
profile: this.currentProfile.name,
|
|
192
|
+
timeoutMs: this.settings.timeout,
|
|
193
|
+
allowInsecureHttp: this.settings.allowInsecureHttp,
|
|
194
|
+
skipSSLVerification: this.getTransportConfig().skipSSLVerification,
|
|
195
|
+
});
|
|
196
|
+
return this.batchManagerInstance;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Build common transport configuration using profile-scoped settings first.
|
|
200
|
+
*/
|
|
201
|
+
getTransportConfig() {
|
|
202
|
+
return {
|
|
203
|
+
skipSSLVerification: this.currentProfile?.skipSSLVerification ?? this.settings.skipSSLVerification,
|
|
204
|
+
allowInsecureHttp: this.settings.allowInsecureHttp,
|
|
205
|
+
timeout: this.settings.timeout,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Emit redacted debug output to stderr.
|
|
210
|
+
*/
|
|
211
|
+
debugLog(message, context) {
|
|
212
|
+
if (!this.shouldEmitDebug()) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const suffix = context && Object.keys(context).length > 0
|
|
216
|
+
? ` ${JSON.stringify(this.redactDebugContext(context))}`
|
|
217
|
+
: '';
|
|
218
|
+
this.logToStderr(`[debug] ${message}${suffix}`);
|
|
219
|
+
}
|
|
220
|
+
shouldEmitDebug() {
|
|
221
|
+
if (!this.debugMode) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return this.explicitDebugMode || !this.quietMode;
|
|
225
|
+
}
|
|
226
|
+
redactDebugContext(context) {
|
|
227
|
+
const sensitiveKeys = ['password', 'secret', 'token', 'authorization', 'cookie', 'apikey'];
|
|
228
|
+
const redacted = {};
|
|
229
|
+
for (const [key, value] of Object.entries(context)) {
|
|
230
|
+
if (sensitiveKeys.includes(key.toLowerCase())) {
|
|
231
|
+
redacted[key] = '[REDACTED]';
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (typeof value === 'string' && value.length > 300) {
|
|
235
|
+
redacted[key] = `${value.slice(0, 297)}...`;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
239
|
+
redacted[key] = this.redactDebugContext(value);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
redacted[key] = value;
|
|
243
|
+
}
|
|
244
|
+
return redacted;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Output data in JSON or human-readable format.
|
|
248
|
+
*
|
|
249
|
+
* @param data - The data to output (used for JSON mode)
|
|
250
|
+
* @param humanFormatter - Optional function that returns human-readable string
|
|
251
|
+
*/
|
|
252
|
+
output(data, humanFormatter) {
|
|
253
|
+
if (this.quietMode) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (this.jsonOutput) {
|
|
257
|
+
const envelope = successOutput(data);
|
|
258
|
+
this.log(JSON.stringify(envelope, null, 2));
|
|
259
|
+
}
|
|
260
|
+
else if (humanFormatter) {
|
|
261
|
+
this.log(humanFormatter());
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Handle errors with appropriate exit codes
|
|
266
|
+
*/
|
|
267
|
+
async catch(err) {
|
|
268
|
+
// Re-throw oclif exit errors to preserve their exit code
|
|
269
|
+
if (err.oclif && typeof err.oclif.exit === 'number') {
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
272
|
+
if (this.jsonOutput) {
|
|
273
|
+
const envelope = errorOutput(err);
|
|
274
|
+
this.log(JSON.stringify(envelope, null, 2));
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// Human-readable error output with hints
|
|
278
|
+
this.logToStderr(formatError(err));
|
|
279
|
+
}
|
|
280
|
+
// Determine exit code from error class (MainWPCTLError subclasses carry exitCode)
|
|
281
|
+
const exitCode = isMainWPCTLError(err) ? err.exitCode : (err.exitCode ?? ExitCode.INTERNAL_ERROR);
|
|
282
|
+
this.exit(exitCode);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=base-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../src/lib/base-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAc,MAAM,aAA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: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Format an error message
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatError(error: Error | string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a warning message
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatWarning(message: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Format an info message
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatInfo(message: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Format a heading
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatHeading(text: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Format a key-value pair
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatKeyValue(key: string, value: unknown): string;
|
|
28
|
+
/**
|
|
29
|
+
* Format a table of data
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatTable(headers: string[], rows: string[][]): string;
|
|
32
|
+
/**
|
|
33
|
+
* Format a list of items
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatList(items: string[], bullet?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format a preview/dry-run result
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatPreview(action: string, affectedItems: unknown): string;
|
|
40
|
+
/**
|
|
41
|
+
* Format a progress bar
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatProgressBar(percent: number, width?: number): string;
|
|
44
|
+
/**
|
|
45
|
+
* Format elapsed time
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatElapsed(ms: number): string;
|
|
48
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/output/formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAgBzD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAKlE;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,EAAE,EAAE,GACf,MAAM,CAgCR;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,SAAM,GAAG,MAAM,CAGhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GACrB,MAAM,CAeR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CASrE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAgBhD"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable output formatter for mainwpcontrol
|
|
3
|
+
*/
|
|
4
|
+
import { isMainWPCTLError } from '../utils/errors.js';
|
|
5
|
+
import { stripControlChars, sanitizeForTerminal, safeString } from '../utils/terminal-sanitizer.js';
|
|
6
|
+
import { colors, color } from '../utils/colors.js';
|
|
7
|
+
/**
|
|
8
|
+
* Format a success message
|
|
9
|
+
*/
|
|
10
|
+
export function formatSuccess(message) {
|
|
11
|
+
return color('✓ ', colors.green) + message;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format an error message
|
|
15
|
+
*/
|
|
16
|
+
export function formatError(error) {
|
|
17
|
+
const message = error instanceof Error ? stripControlChars(error.message) : stripControlChars(error);
|
|
18
|
+
let output = color('✗ Error: ', colors.red, colors.bold) + message;
|
|
19
|
+
if (isMainWPCTLError(error)) {
|
|
20
|
+
if (error.details) {
|
|
21
|
+
// Sanitize error details before display (untrusted API data)
|
|
22
|
+
const sanitizedDetails = sanitizeForTerminal(error.details);
|
|
23
|
+
output += '\n' + color(' Details: ', colors.dim) + JSON.stringify(sanitizedDetails);
|
|
24
|
+
}
|
|
25
|
+
if (error.hint) {
|
|
26
|
+
output += '\n' + color('💡 ' + stripControlChars(error.hint), colors.dim);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return output;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Format a warning message
|
|
33
|
+
*/
|
|
34
|
+
export function formatWarning(message) {
|
|
35
|
+
return color('⚠ Warning: ', colors.yellow) + stripControlChars(message);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Format an info message
|
|
39
|
+
*/
|
|
40
|
+
export function formatInfo(message) {
|
|
41
|
+
return color('ℹ ', colors.blue) + message;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Format a heading
|
|
45
|
+
*/
|
|
46
|
+
export function formatHeading(text) {
|
|
47
|
+
return color(text, colors.bold, colors.cyan);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format a key-value pair
|
|
51
|
+
*/
|
|
52
|
+
export function formatKeyValue(key, value) {
|
|
53
|
+
// Sanitize both key and value (may contain untrusted API data)
|
|
54
|
+
const safeKey = stripControlChars(key);
|
|
55
|
+
const valueStr = safeString(value);
|
|
56
|
+
return color(safeKey + ': ', colors.dim) + valueStr;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Format a table of data
|
|
60
|
+
*/
|
|
61
|
+
export function formatTable(headers, rows) {
|
|
62
|
+
if (rows.length === 0) {
|
|
63
|
+
return '(no data)';
|
|
64
|
+
}
|
|
65
|
+
// Sanitize all table data (may contain untrusted API data)
|
|
66
|
+
const safeHeaders = headers.map((h) => stripControlChars(h));
|
|
67
|
+
const safeRows = rows.map((row) => row.map((cell) => stripControlChars(cell ?? '')));
|
|
68
|
+
// Calculate column widths using sanitized data
|
|
69
|
+
const widths = safeHeaders.map((h, i) => {
|
|
70
|
+
const rowWidths = safeRows.map((r) => (r[i] ?? '').length);
|
|
71
|
+
return Math.max(h.length, ...rowWidths);
|
|
72
|
+
});
|
|
73
|
+
// Format header
|
|
74
|
+
const headerLine = safeHeaders
|
|
75
|
+
.map((h, i) => h.padEnd(widths[i] ?? 0))
|
|
76
|
+
.join(' ');
|
|
77
|
+
const separator = widths.map((w) => '-'.repeat(w)).join(' ');
|
|
78
|
+
// Format rows
|
|
79
|
+
const dataLines = safeRows.map((row) => row.map((cell, i) => (cell ?? '').padEnd(widths[i] ?? 0)).join(' '));
|
|
80
|
+
return [
|
|
81
|
+
color(headerLine, colors.bold),
|
|
82
|
+
separator,
|
|
83
|
+
...dataLines,
|
|
84
|
+
].join('\n');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Format a list of items
|
|
88
|
+
*/
|
|
89
|
+
export function formatList(items, bullet = '•') {
|
|
90
|
+
// Sanitize list items (may contain untrusted API data)
|
|
91
|
+
return items.map((item) => ` ${bullet} ${stripControlChars(item)}`).join('\n');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Format a preview/dry-run result
|
|
95
|
+
*/
|
|
96
|
+
export function formatPreview(action, affectedItems) {
|
|
97
|
+
// Sanitize preview data (may contain untrusted API data)
|
|
98
|
+
const sanitizedItems = sanitizeForTerminal(affectedItems);
|
|
99
|
+
const lines = [
|
|
100
|
+
color('Preview: ', colors.yellow, colors.bold) + stripControlChars(action),
|
|
101
|
+
'',
|
|
102
|
+
color('Affected items:', colors.dim),
|
|
103
|
+
JSON.stringify(sanitizedItems, null, 2),
|
|
104
|
+
'',
|
|
105
|
+
color('This is a preview. No changes have been made.', colors.yellow),
|
|
106
|
+
'To execute, run the command with --confirm',
|
|
107
|
+
];
|
|
108
|
+
return lines.join('\n');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Format a progress bar
|
|
112
|
+
*/
|
|
113
|
+
export function formatProgressBar(percent, width = 20) {
|
|
114
|
+
const clampedPercent = Math.max(0, Math.min(100, percent));
|
|
115
|
+
const filled = Math.round((clampedPercent / 100) * width);
|
|
116
|
+
const empty = width - filled;
|
|
117
|
+
const bar = '█'.repeat(filled) + '░'.repeat(empty);
|
|
118
|
+
const percentStr = `${clampedPercent}%`.padStart(4);
|
|
119
|
+
return `[${bar}] ${percentStr}`;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Format elapsed time
|
|
123
|
+
*/
|
|
124
|
+
export function formatElapsed(ms) {
|
|
125
|
+
const seconds = Math.floor(ms / 1000);
|
|
126
|
+
const minutes = Math.floor(seconds / 60);
|
|
127
|
+
const hours = Math.floor(minutes / 60);
|
|
128
|
+
if (hours > 0) {
|
|
129
|
+
const remainingMinutes = minutes % 60;
|
|
130
|
+
return `${hours}h ${remainingMinutes}m`;
|
|
131
|
+
}
|
|
132
|
+
if (minutes > 0) {
|
|
133
|
+
const remainingSeconds = seconds % 60;
|
|
134
|
+
return `${minutes}m ${remainingSeconds}s`;
|
|
135
|
+
}
|
|
136
|
+
return `${seconds}s`;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/output/formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAA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I,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IAEvC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,gBAAgB,GAAG,OAAO,GAAG,EAAE,CAAC;QACtC,OAAO,GAAG,KAAK,KAAK,gBAAgB,GAAG,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,MAAM,gBAAgB,GAAG,OAAO,GAAG,EAAE,CAAC;QACtC,OAAO,GAAG,OAAO,KAAK,gBAAgB,GAAG,CAAC;IAC5C,CAAC;IAED,OAAO,GAAG,OAAO,GAAG,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON output envelope for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* This structure is stable and should not be changed without a major version bump.
|
|
5
|
+
*/
|
|
6
|
+
import { type MainWPCTLError } from '../utils/errors.js';
|
|
7
|
+
/**
|
|
8
|
+
* Stable CLI output envelope
|
|
9
|
+
*/
|
|
10
|
+
export interface CLIOutput<T = unknown> {
|
|
11
|
+
success: boolean;
|
|
12
|
+
data?: T;
|
|
13
|
+
error?: {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
details?: unknown;
|
|
17
|
+
hint?: string;
|
|
18
|
+
};
|
|
19
|
+
meta?: {
|
|
20
|
+
command: string;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a success response
|
|
27
|
+
*/
|
|
28
|
+
export declare function successOutput<T>(data: T, meta?: {
|
|
29
|
+
command: string;
|
|
30
|
+
version: string;
|
|
31
|
+
}): CLIOutput<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Create an error response
|
|
34
|
+
*/
|
|
35
|
+
export declare function errorOutput(error: MainWPCTLError | Error | string, meta?: {
|
|
36
|
+
command: string;
|
|
37
|
+
version: string;
|
|
38
|
+
}): CLIOutput<never>;
|
|
39
|
+
/**
|
|
40
|
+
* Format output as JSON string
|
|
41
|
+
*/
|
|
42
|
+
export declare function formatJSON<T>(output: CLIOutput<T>): string;
|
|
43
|
+
//# sourceMappingURL=json-envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-envelope.d.ts","sourceRoot":"","sources":["../../src/output/json-envelope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG3E;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,IAAI,CAAC,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C,SAAS,CAAC,CAAC,CAAC,CAkBd;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,cAAc,GAAG,KAAK,GAAG,MAAM,EACtC,IAAI,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C,SAAS,CAAC,KAAK,CAAC,CAsClB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON output envelope for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* This structure is stable and should not be changed without a major version bump.
|
|
5
|
+
*/
|
|
6
|
+
import { isMainWPCTLError } from '../utils/errors.js';
|
|
7
|
+
import { sanitizeForTerminal, stripControlChars } from '../utils/terminal-sanitizer.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create a success response
|
|
10
|
+
*/
|
|
11
|
+
export function successOutput(data, meta) {
|
|
12
|
+
// Sanitize data to prevent terminal escape injection in piped JSON
|
|
13
|
+
const sanitizedData = sanitizeForTerminal(data);
|
|
14
|
+
const output = {
|
|
15
|
+
success: true,
|
|
16
|
+
data: sanitizedData,
|
|
17
|
+
};
|
|
18
|
+
if (meta) {
|
|
19
|
+
output.meta = {
|
|
20
|
+
command: meta.command,
|
|
21
|
+
timestamp: new Date().toISOString(),
|
|
22
|
+
version: meta.version,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return output;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create an error response
|
|
29
|
+
*/
|
|
30
|
+
export function errorOutput(error, meta) {
|
|
31
|
+
let errorBody;
|
|
32
|
+
if (isMainWPCTLError(error)) {
|
|
33
|
+
errorBody = {
|
|
34
|
+
code: error.code,
|
|
35
|
+
message: stripControlChars(error.message),
|
|
36
|
+
details: error.details ? sanitizeForTerminal(error.details) : undefined,
|
|
37
|
+
};
|
|
38
|
+
if (error.hint) {
|
|
39
|
+
errorBody.hint = stripControlChars(error.hint);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (error instanceof Error) {
|
|
43
|
+
errorBody = {
|
|
44
|
+
code: 'INTERNAL_ERROR',
|
|
45
|
+
message: stripControlChars(error.message),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
errorBody = {
|
|
50
|
+
code: 'INTERNAL_ERROR',
|
|
51
|
+
message: stripControlChars(String(error)),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const output = {
|
|
55
|
+
success: false,
|
|
56
|
+
error: errorBody,
|
|
57
|
+
};
|
|
58
|
+
if (meta) {
|
|
59
|
+
output.meta = {
|
|
60
|
+
command: meta.command,
|
|
61
|
+
timestamp: new Date().toISOString(),
|
|
62
|
+
version: meta.version,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return output;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Format output as JSON string
|
|
69
|
+
*/
|
|
70
|
+
export function formatJSON(output) {
|
|
71
|
+
return JSON.stringify(output, null, 2);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=json-envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-envelope.js","sourceRoot":"","sources":["../../src/output/json-envelope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAuB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAqBxF;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAO,EACP,IAA2C;IAE3C,mEAAmE;IACnE,MAAM,aAAa,GAAG,mBAAmB,CAAC,IAAI,CAAM,CAAC;IAErD,MAAM,MAAM,GAAiB;QAC3B,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,aAAa;KACpB,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,CAAC,IAAI,GAAG;YACZ,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE,CAA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