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

Function resolveOpenSpecRoot

src/core/root-selection.ts:349–405  ·  view source on GitHub ↗
(
  options: ResolveOpenSpecRootOptions = {}
)

Source from the content-addressed store, hash-verified

347}
348
349export async function resolveOpenSpecRoot(
350 options: ResolveOpenSpecRootOptions = {}
351): Promise<ResolvedOpenSpecRoot> {
352 if (options.storePath !== undefined) {
353 throw new RootSelectionError(
354 '--store-path is not supported. Register the path with openspec store register <path>, then select it with --store <id>.',
355 'store_path_not_supported',
356 {
357 target: 'store.id',
358 fix: 'openspec store register <path>, then rerun with --store <id>.',
359 }
360 );
361 }
362
363 if (options.store !== undefined) {
364 return resolveStoreRoot(options.store, options.globalDataDir);
365 }
366
367 const startPath = options.startPath ?? process.cwd();
368 const nearestRoot = findQualifyingRootSync(startPath);
369 if (nearestRoot) {
370 return resolveNearestOrDeclaredRoot(nearestRoot, options.globalDataDir);
371 }
372
373 let registry;
374 try {
375 registry = await readStoreRegistryState(
376 options.globalDataDir ? { globalDataDir: options.globalDataDir } : {}
377 );
378 } catch (error) {
379 fromStoreError(error);
380 }
381 const registeredIds = registry
382 ? listStoreRegistryEntries(registry).map((entry) => entry.id)
383 : [];
384
385 if (registeredIds.length > 0) {
386 throw new RootSelectionError(
387 `No OpenSpec root found in the current directory or its ancestors. Registered stores: ${registeredIds.join(', ')}. Pass --store <id> to use one, or run openspec init to create a local root.`,
388 'no_root_with_registered_stores',
389 {
390 target: 'openspec.root',
391 fix: `Rerun with --store <id> (registered: ${registeredIds.join(', ')}) or run openspec init.`,
392 }
393 );
394 }
395
396 if (options.allowImplicitRoot === false) {
397 throw new RootSelectionError(
398 'No OpenSpec root found from the current directory.',
399 'no_openspec_root',
400 { target: 'openspec.root', fix: 'Run openspec init to create a root here.' }
401 );
402 }
403
404 return makeRoot(canonicalDirectory(startPath), 'implicit');
405}
406

Callers 3

resolveRootForCommandFunction · 0.85
executeMethod · 0.85

Calls 8

resolveStoreRootFunction · 0.85
findQualifyingRootSyncFunction · 0.85
readStoreRegistryStateFunction · 0.85
fromStoreErrorFunction · 0.85
listStoreRegistryEntriesFunction · 0.85
makeRootFunction · 0.85
canonicalDirectoryFunction · 0.85

Tested by

no test coverage detected