MCPcopy Create free account
hub / github.com/chhoumann/quickadd / detectUserScriptSecretOptions

Function detectUserScriptSecretOptions

src/utils/userScriptSecrets.ts:434–494  ·  view source on GitHub ↗
(
	source: string,
	path?: string,
)

Source from the content-addressed store, hash-verified

432}
433
434export function detectUserScriptSecretOptions(
435 source: string,
436 path?: string,
437): UserScriptSecretOptionDetection {
438 const sourceToInspect =
439 path && MARKDOWN_FILE_EXTENSION_REGEX.test(path)
440 ? (extractScriptFromMarkdown(source).code ?? "")
441 : source;
442 const names = new Set<string>();
443 let foundSecretOptions = false;
444 const constants = collectStringConstants(sourceToInspect);
445
446 for (const { start, end } of findOptionsObjectSpans(sourceToInspect)) {
447 let current = start;
448
449 while (current < end) {
450 current = skipWhitespaceAndComments(sourceToInspect, current);
451 if (sourceToInspect[current] === ",") {
452 current += 1;
453 continue;
454 }
455 if (current >= end) break;
456
457 const key = readOptionKey(sourceToInspect, current, constants);
458 if (!key) {
459 current += 1;
460 continue;
461 }
462
463 current = skipWhitespaceAndComments(sourceToInspect, key.end);
464 if (sourceToInspect[current] !== ":") {
465 current += 1;
466 continue;
467 }
468
469 current = skipWhitespaceAndComments(sourceToInspect, current + 1);
470 if (sourceToInspect[current] !== "{") {
471 current += 1;
472 continue;
473 }
474
475 const valueEnd = findMatchingDelimiter(
476 sourceToInspect,
477 current,
478 "{",
479 "}",
480 );
481 if (valueEnd === -1 || valueEnd > end) break;
482
483 const body = sourceToInspect.slice(current + 1, valueEnd);
484 if (optionBodyDeclaresSecret(body)) {
485 foundSecretOptions = true;
486 if (key.name) names.add(key.name);
487 }
488
489 current = valueEnd + 1;
490 }
491 }

Calls 8

collectStringConstantsFunction · 0.85
findOptionsObjectSpansFunction · 0.85
readOptionKeyFunction · 0.85
findMatchingDelimiterFunction · 0.85
optionBodyDeclaresSecretFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected