opencode-1password-auth 1.0.16 → 1.0.17
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 +105 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -4
- package/dist/index.js.map +1 -1
- package/dist/src/command-matcher.d.ts +34 -0
- package/dist/src/command-matcher.d.ts.map +1 -0
- package/dist/src/command-matcher.js +171 -0
- package/dist/src/command-matcher.js.map +1 -0
- package/dist/src/config.d.ts +16 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +82 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/desktop-detection.d.ts +20 -0
- package/dist/src/desktop-detection.d.ts.map +1 -0
- package/dist/src/desktop-detection.js +48 -0
- package/dist/src/desktop-detection.js.map +1 -0
- package/dist/src/fallback.d.ts +15 -0
- package/dist/src/fallback.d.ts.map +1 -0
- package/dist/src/fallback.js +184 -0
- package/dist/src/fallback.js.map +1 -0
- package/dist/src/logging.d.ts +21 -0
- package/dist/src/logging.d.ts.map +1 -0
- package/dist/src/logging.js +141 -0
- package/dist/src/logging.js.map +1 -0
- package/dist/src/orchestration.d.ts +37 -0
- package/dist/src/orchestration.d.ts.map +1 -0
- package/dist/src/orchestration.js +175 -0
- package/dist/src/orchestration.js.map +1 -0
- package/dist/src/validation.d.ts +26 -0
- package/dist/src/validation.d.ts.map +1 -0
- package/dist/src/validation.js +113 -0
- package/dist/src/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import config from './config.js';
|
|
2
|
+
import { shouldValidateCommand } from './command-matcher.js';
|
|
3
|
+
import { isDesktopAppAvailable, getMountedEnvPath } from './desktop-detection.js';
|
|
4
|
+
import { validateMountedEnvFiles } from './validation.js';
|
|
5
|
+
import { fallbackToServiceAccount } from './fallback.js';
|
|
6
|
+
import { validationDebug, validationInfo, validationWarn, validationError, } from './logging.js';
|
|
7
|
+
/**
|
|
8
|
+
* Helper to wrap a promise with a timeout.
|
|
9
|
+
* Returns the promise result if it resolves before timeout, otherwise throws.
|
|
10
|
+
*/
|
|
11
|
+
async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
12
|
+
if (timeoutMs <= 0) {
|
|
13
|
+
return promise;
|
|
14
|
+
}
|
|
15
|
+
return Promise.race([
|
|
16
|
+
promise,
|
|
17
|
+
new Promise((_, reject) => {
|
|
18
|
+
setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Orchestrates validation of a shell command against 1Password secrets.
|
|
24
|
+
*
|
|
25
|
+
* Follows the orchestration pattern from index.ts:162-173 (readEnvironmentVariables)
|
|
26
|
+
* and error handling pattern from index.ts:117-160 (multiple fallback strategies).
|
|
27
|
+
*
|
|
28
|
+
* Steps:
|
|
29
|
+
* 1. Check if command matches validation patterns (using shouldValidateCommand)
|
|
30
|
+
* 2. If not, returns skipped result with reason 'command_not_matched'
|
|
31
|
+
* 3. Check if desktop app is available (isDesktopAppAvailable)
|
|
32
|
+
* 4. If not, attempts fallback to Service Account validation (fallbackToServiceAccount)
|
|
33
|
+
* 5. If desktop app available, get mounted environment path (getMountedEnvPath)
|
|
34
|
+
* 6. Validate FIFO files at that path (validateMountedEnvFiles)
|
|
35
|
+
* 7. Handle timeouts and errors gracefully
|
|
36
|
+
* 8. Return comprehensive result with status and metadata
|
|
37
|
+
*
|
|
38
|
+
* @param command - The shell command to validate
|
|
39
|
+
* @returns Promise<OrchestrationResult> Validation result with metadata
|
|
40
|
+
*/
|
|
41
|
+
export async function validateCommand(command) {
|
|
42
|
+
const startTime = Date.now();
|
|
43
|
+
validationDebug(`Starting orchestration for command: ${command.substring(0, 200)}${command.length > 200 ? '...' : ''}`);
|
|
44
|
+
// Base result structure
|
|
45
|
+
const result = {
|
|
46
|
+
isValid: true,
|
|
47
|
+
invalidFiles: [],
|
|
48
|
+
errors: [],
|
|
49
|
+
skipped: [],
|
|
50
|
+
desktopAppAvailable: false,
|
|
51
|
+
fallbackAttempted: false,
|
|
52
|
+
};
|
|
53
|
+
// Helper to add error and mark invalid
|
|
54
|
+
const addError = (error, file) => {
|
|
55
|
+
result.isValid = false;
|
|
56
|
+
if (file && !result.invalidFiles.includes(file)) {
|
|
57
|
+
result.invalidFiles.push(file);
|
|
58
|
+
}
|
|
59
|
+
result.errors.push({ file: file || '', error });
|
|
60
|
+
validationError(`Orchestration error: ${error}`, undefined, { file });
|
|
61
|
+
};
|
|
62
|
+
// Helper to add skipped file (for FIFO validation)
|
|
63
|
+
const addSkippedFile = (file, reason) => {
|
|
64
|
+
result.skipped.push(file);
|
|
65
|
+
validationDebug(`Skipped file ${file}: ${reason}`);
|
|
66
|
+
};
|
|
67
|
+
// Core validation logic that can be wrapped with timeout
|
|
68
|
+
const executeValidation = async () => {
|
|
69
|
+
// 1. Check if command matches validation patterns
|
|
70
|
+
if (!shouldValidateCommand(command, config.commandPatterns)) {
|
|
71
|
+
result.skippedReason = 'command_not_matched';
|
|
72
|
+
validationDebug(`Command does not match validation patterns, skipping orchestration`);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
// 2. Check desktop app availability
|
|
76
|
+
const desktopAppAvailable = isDesktopAppAvailable();
|
|
77
|
+
result.desktopAppAvailable = desktopAppAvailable;
|
|
78
|
+
validationDebug(`Desktop app available: ${desktopAppAvailable}`);
|
|
79
|
+
if (!desktopAppAvailable) {
|
|
80
|
+
// 3. Fallback to Service Account validation
|
|
81
|
+
validationWarn('Desktop app not available, attempting fallback to Service Account');
|
|
82
|
+
result.fallbackAttempted = true;
|
|
83
|
+
try {
|
|
84
|
+
const fallbackSuccess = await fallbackToServiceAccount();
|
|
85
|
+
result.fallbackSuccess = fallbackSuccess;
|
|
86
|
+
if (fallbackSuccess) {
|
|
87
|
+
validationInfo('Fallback validation succeeded');
|
|
88
|
+
// Consider validation passed
|
|
89
|
+
result.isValid = true;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
result.skippedReason = 'fallback_failed';
|
|
93
|
+
validationWarn('Fallback validation failed');
|
|
94
|
+
// We don't mark as invalid because fallback failure shouldn't block execution
|
|
95
|
+
// (config.blockOnFailure will decide later)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (fallbackError) {
|
|
99
|
+
result.fallbackSuccess = false;
|
|
100
|
+
result.skippedReason = 'fallback_failed';
|
|
101
|
+
validationError('Fallback validation threw an error', fallbackError);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
// 4. Desktop app available - get mounted environment path
|
|
106
|
+
const mountedEnvPath = getMountedEnvPath();
|
|
107
|
+
result.mountedEnvPath = mountedEnvPath || undefined;
|
|
108
|
+
if (!mountedEnvPath) {
|
|
109
|
+
result.skippedReason = 'no_mounted_path';
|
|
110
|
+
validationWarn('Could not determine mounted environment path');
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
// 5. Validate FIFO files
|
|
114
|
+
validationDebug(`Validating FIFO files at: ${mountedEnvPath}`);
|
|
115
|
+
try {
|
|
116
|
+
const fifoResult = await validateMountedEnvFiles(mountedEnvPath, config.validationTimeout);
|
|
117
|
+
// Merge FIFO validation results into our result
|
|
118
|
+
result.isValid = fifoResult.isValid;
|
|
119
|
+
result.invalidFiles = fifoResult.invalidFiles;
|
|
120
|
+
result.errors = fifoResult.errors;
|
|
121
|
+
result.skipped = fifoResult.skipped;
|
|
122
|
+
if (!result.isValid) {
|
|
123
|
+
validationError(`FIFO validation failed: ${result.errors.map(e => e.error).join(', ')}`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
validationInfo('FIFO validation passed');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
// Unexpected error during FIFO validation
|
|
131
|
+
addError(`Unexpected error during FIFO validation: ${error instanceof Error ? error.message : String(error)}`);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
};
|
|
135
|
+
// Apply timeout to the entire orchestration
|
|
136
|
+
// Use validationTimeout + buffer for fallback and overhead
|
|
137
|
+
const orchestrationTimeoutMs = config.validationTimeout + 5000;
|
|
138
|
+
try {
|
|
139
|
+
await withTimeout(executeValidation(), orchestrationTimeoutMs, `Orchestration timeout after ${orchestrationTimeoutMs}ms`);
|
|
140
|
+
}
|
|
141
|
+
catch (timeoutError) {
|
|
142
|
+
// Handle timeout - treat as validation failure
|
|
143
|
+
addError(`Orchestration timeout: ${timeoutError instanceof Error ? timeoutError.message : String(timeoutError)}`);
|
|
144
|
+
}
|
|
145
|
+
logOrchestrationResult(command, result, Date.now() - startTime);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Logs orchestration result with timing.
|
|
150
|
+
*/
|
|
151
|
+
function logOrchestrationResult(command, result, durationMs) {
|
|
152
|
+
const context = {
|
|
153
|
+
commandSnippet: command.substring(0, 100),
|
|
154
|
+
durationMs,
|
|
155
|
+
isValid: result.isValid,
|
|
156
|
+
skippedReason: result.skippedReason,
|
|
157
|
+
desktopAppAvailable: result.desktopAppAvailable,
|
|
158
|
+
mountedEnvPath: result.mountedEnvPath,
|
|
159
|
+
fallbackAttempted: result.fallbackAttempted,
|
|
160
|
+
fallbackSuccess: result.fallbackSuccess,
|
|
161
|
+
errorCount: result.errors.length,
|
|
162
|
+
invalidFileCount: result.invalidFiles.length,
|
|
163
|
+
skippedFileCount: result.skipped.length,
|
|
164
|
+
};
|
|
165
|
+
if (!result.isValid) {
|
|
166
|
+
validationError(`Orchestration failed`, undefined, context);
|
|
167
|
+
}
|
|
168
|
+
else if (result.skippedReason) {
|
|
169
|
+
validationWarn(`Orchestration skipped: ${result.skippedReason}`, context);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
validationInfo(`Orchestration completed successfully`, context);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=orchestration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestration.js","sourceRoot":"","sources":["../../src/orchestration.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAA4C,MAAM,iBAAiB,CAAC;AACpG,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,KAAK,UAAU,WAAW,CACxB,OAAmB,EACnB,SAAiB,EACjB,cAAsB;IAEtB,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,OAAO;QACP,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;YAC/B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACjE,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAkBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAe;IACnD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,eAAe,CAAC,uCAAuC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAExH,wBAAwB;IACxB,MAAM,MAAM,G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+
skipped: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates FIFO files in the mounted environments directory.
|
|
12
|
+
*
|
|
13
|
+
* Checks each file in the mountPath directory for:
|
|
14
|
+
* - Existence
|
|
15
|
+
* - Is a FIFO (named pipe)
|
|
16
|
+
* - Readability (can be opened for reading)
|
|
17
|
+
*
|
|
18
|
+
* Uses timeout to prevent indefinite blocking. If timeout is reached,
|
|
19
|
+
* validation fails with timeout error.
|
|
20
|
+
*
|
|
21
|
+
* @param mountPath Path to the mounted environments directory (e.g., ~/.1password/mounted/envs/)
|
|
22
|
+
* @param timeout Timeout in milliseconds (optional, default 5000)
|
|
23
|
+
* @returns Promise<ValidationResult> Validation results
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateMountedEnvFiles(mountPath: string, timeout?: number): Promise<ValidationResult>;
|
|
26
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAqG3B"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { validationDebug, validationError, validationInfo, } from './logging.js';
|
|
4
|
+
/**
|
|
5
|
+
* Validates FIFO files in the mounted environments directory.
|
|
6
|
+
*
|
|
7
|
+
* Checks each file in the mountPath directory for:
|
|
8
|
+
* - Existence
|
|
9
|
+
* - Is a FIFO (named pipe)
|
|
10
|
+
* - Readability (can be opened for reading)
|
|
11
|
+
*
|
|
12
|
+
* Uses timeout to prevent indefinite blocking. If timeout is reached,
|
|
13
|
+
* validation fails with timeout error.
|
|
14
|
+
*
|
|
15
|
+
* @param mountPath Path to the mounted environments directory (e.g., ~/.1password/mounted/envs/)
|
|
16
|
+
* @param timeout Timeout in milliseconds (optional, default 5000)
|
|
17
|
+
* @returns Promise<ValidationResult> Validation results
|
|
18
|
+
*/
|
|
19
|
+
export async function validateMountedEnvFiles(mountPath, timeout) {
|
|
20
|
+
const timeoutMs = timeout ?? 5000;
|
|
21
|
+
validationDebug(`Starting FIFO validation for mount path: ${mountPath}`, { timeoutMs });
|
|
22
|
+
const result = {
|
|
23
|
+
isValid: true,
|
|
24
|
+
invalidFiles: [],
|
|
25
|
+
errors: [],
|
|
26
|
+
skipped: [],
|
|
27
|
+
};
|
|
28
|
+
// Helper to add error
|
|
29
|
+
const addError = (file, error) => {
|
|
30
|
+
result.isValid = false;
|
|
31
|
+
if (file) {
|
|
32
|
+
result.invalidFiles.push(file);
|
|
33
|
+
}
|
|
34
|
+
result.errors.push({ file, error });
|
|
35
|
+
validationError(`Validation error for file ${file}: ${error}`);
|
|
36
|
+
};
|
|
37
|
+
// Helper to add skipped file
|
|
38
|
+
const addSkipped = (file, reason) => {
|
|
39
|
+
result.skipped.push(file);
|
|
40
|
+
validationDebug(`Skipped file ${file}: ${reason}`);
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
// Check if mountPath exists and is a directory
|
|
44
|
+
if (!fs.existsSync(mountPath)) {
|
|
45
|
+
addError('', `Mount path does not exist: ${mountPath}`);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const stat = fs.statSync(mountPath);
|
|
49
|
+
if (!stat.isDirectory()) {
|
|
50
|
+
addError('', `Mount path is not a directory: ${mountPath}`);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
// Read directory entries
|
|
54
|
+
const entries = fs.readdirSync(mountPath);
|
|
55
|
+
validationDebug(`Found ${entries.length} entries in mount path`, { entries });
|
|
56
|
+
// Process each entry with timeout protection
|
|
57
|
+
const validationPromise = (async () => {
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
const filePath = path.join(mountPath, entry);
|
|
60
|
+
try {
|
|
61
|
+
// Skip directories and symlinks, only check regular files/FIFOs
|
|
62
|
+
const fileStat = fs.statSync(filePath);
|
|
63
|
+
if (!fileStat.isFile() && !fileStat.isFIFO()) {
|
|
64
|
+
addSkipped(entry, 'Not a regular file or FIFO');
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// Check if it's a FIFO
|
|
68
|
+
if (!fileStat.isFIFO()) {
|
|
69
|
+
addError(entry, 'Not a FIFO (named pipe)');
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Check readability
|
|
73
|
+
try {
|
|
74
|
+
const fd = fs.openSync(filePath, 'r');
|
|
75
|
+
fs.closeSync(fd);
|
|
76
|
+
validationDebug(`File ${entry} passed FIFO validation`);
|
|
77
|
+
}
|
|
78
|
+
catch (openErr) {
|
|
79
|
+
addError(entry, `Cannot open for reading: ${openErr instanceof Error ? openErr.message : String(openErr)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (statErr) {
|
|
83
|
+
addError(entry, `Failed to stat file: ${statErr instanceof Error ? statErr.message : String(statErr)}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
// Race between validation and timeout
|
|
88
|
+
await Promise.race([
|
|
89
|
+
validationPromise,
|
|
90
|
+
new Promise((_, reject) => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
reject(new Error(`FIFO validation timeout after ${timeoutMs}ms`));
|
|
93
|
+
}, timeoutMs);
|
|
94
|
+
}),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
// This catches timeout or any other unexpected error
|
|
99
|
+
if (err instanceof Error && err.message.includes('timeout')) {
|
|
100
|
+
addError('', `Validation timeout: ${err.message}`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
addError('', `Unexpected validation error: ${err instanceof Error ? err.message : String(err)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
validationInfo(`FIFO validation completed: ${result.isValid ? 'PASS' : 'FAIL'}`, {
|
|
107
|
+
invalidFiles: result.invalidFiles.length,
|
|
108
|
+
errors: result.errors.length,
|
|
109
|
+
skipped: result.skipped.length,
|
|
110
|
+
});
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,eAAe,EACf,eAAe,EACf,cAAc,GACf,MAAM,cAAc,CAAC;AAStB;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,SAAiB,EACjB,OAAgB;IAEhB,MAAM,SAAS,GAAG,OAAO,IAAI,IAAI,CAAC;IAClC,eAAe,CAAC,4CAA4C,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAExF,MAAM,MAAM,GAAqB;QAC/B,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,sBAAsB;IACtB,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;QAC/C,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,IAAI,IAAI,EAAE,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