MCPcopy
hub / github.com/Fission-AI/OpenSpec / resolveRootForCommand

Function resolveRootForCommand

src/core/root-selection.ts:476–516  ·  view source on GitHub ↗
(
  selector: StoreSelectorOptions,
  output: {
    json?: boolean;
    failurePayload?: Record<string, unknown>;
    /** Diagnostic commands inspect what exists; they never scaffold. */
    allowImplicitRoot?: boolean;
  } = {}
)

Source from the content-addressed store, hash-verified

474 * standard error handling so message text and exit behavior stay consistent.
475 */
476export async function resolveRootForCommand(
477 selector: StoreSelectorOptions,
478 output: {
479 json?: boolean;
480 failurePayload?: Record<string, unknown>;
481 /** Diagnostic commands inspect what exists; they never scaffold. */
482 allowImplicitRoot?: boolean;
483 } = {}
484): Promise<ResolvedOpenSpecRoot | null> {
485 try {
486 const root = await resolveOpenSpecRoot({
487 ...(selector.store !== undefined ? { store: selector.store } : {}),
488 ...(selector.storePath !== undefined ? { storePath: selector.storePath } : {}),
489 ...(output.allowImplicitRoot !== undefined
490 ? { allowImplicitRoot: output.allowImplicitRoot }
491 : {}),
492 });
493
494 // Emitted at resolution time so the banner survives command failures
495 // that happen after the root was successfully selected.
496 if (!output.json) {
497 emitStoreRootBanner(root);
498 }
499
500 return root;
501 } catch (error) {
502 if (output.json && isRootSelectionError(error)) {
503 console.log(
504 JSON.stringify(
505 { ...(output.failurePayload ?? {}), status: [error.diagnostic] },
506 null,
507 2
508 )
509 );
510 process.exitCode = 1;
511 return null;
512 }
513
514 throw error;
515 }
516}

Callers 9

registerDoctorCommandFunction · 0.85
registerContextCommandFunction · 0.85
executeMethod · 0.85
executeMethod · 0.85
instructionsCommandFunction · 0.85
applyInstructionsCommandFunction · 0.85
statusCommandFunction · 0.85
newChangeCommandFunction · 0.85
index.tsFile · 0.85

Calls 3

resolveOpenSpecRootFunction · 0.85
emitStoreRootBannerFunction · 0.85
isRootSelectionErrorFunction · 0.85

Tested by

no test coverage detected