/** * scope-access — per-run scope + datastore readers. * * Extracted from `cli-context.ts` so that module stays focused on context * ASSEMBLY (live-view registry + `buildToolCliContext`). This module owns the * complementary concern: reading the entered `RunScope` and opening the * project-local SQLite datastore lazily. * * After Phase 3 hygiene the ONLY way to obtain the per-run scope is * `currentScope()` (entered by the pre-action-hook, or explicit `runWithScope` * in tests). There are no holder fallbacks. Non-action paths (report, errors) * that need scope must ensure entry or restructure to run inside an entered * action. */ import { type Logger, type ProjectContext, type RunScope, type RuntimePaths } from '@opensip-cli/core'; import { type DataStore, type DatastoreCloseResult } from '@opensip-cli/datastore'; /** * Strict reader: the only way to obtain the per-run scope is `currentScope()` * (entered by pre-action-hook or explicit runWithScope in tests). All previous * holder fallbacks were removed. * * @throws {SystemError} (`SYSTEM.SCOPE.NOT_ENTERED`) When accessed before the * pre-action-hook constructed and entered the scope. */ export declare function readScope(): RunScope; /** * Read the current project root. Convenience for non-tool bootstrap * helpers (e.g. `maybeOpenReport`) that need the project root but * don't carry a ToolCliContext. * * @throws {SystemError} (`SYSTEM.BOOTSTRAP.PROJECT_UNSET`) When accessed before * the pre-action-hook resolved the context. */ export declare function getCurrentProjectRoot(): string; /** * Runtime-state paths for the CURRENT run — project-local when initialized, * user-cache when ephemeral (no-init). * * Prefer this over `resolveProjectPaths(getCurrentProjectRoot())`: the latter * throws away the scope, so an ephemeral run writes runtime state into the * user's repository. That is exactly how `report` came to create * `opensip-cli/.runtime/reports/` in a project the user never initialized. * * @throws {SystemError} When accessed before the pre-action-hook resolved the context. */ export declare function getCurrentRuntimePaths(): RuntimePaths; /** * A lazy datastore accessor (callable) that also exposes a `dispose()` to close * the cached connection on scope teardown. Still assignable to the kernel's * `DataStoreThunk` (`() => unknown`) — `dispose` is additive. */ export interface DatastoreThunk { (): DataStore; /** Return the cached store without materializing SQLite. */ current: () => DataStore | undefined; /** * Close the cached connection (no-op if it was never opened). An arrow-type * property, not a method, so it can be passed straight to `scope.onDispose` * (no unbound-method footgun) while still being assignable on construction. */ dispose: () => DatastoreCloseResult; } /** * Build a closure-based datastore thunk for the given project. * Caches the open DataStore on first access. The pre-action-hook * wires the result into `RunScope.datastore` so tools and CLI * commands reach the same instance. * * @throws {SystemError} (`SYSTEM.BOOTSTRAP.DATASTORE_OUTSIDE_PROJECT`) When the * returned thunk is invoked outside a runtime-backed project scope — callers * must check the command scope first or handle the throw as a "no project * found" error. */ export declare function buildDatastoreThunk(project: ProjectContext, log?: Logger, commandName?: string): DatastoreThunk; /** * Open (or return cached) project-local SQLite DataStore via the * scope's datastore thunk. Shared between tool action bodies and * the host commands (e.g. `sessions`, in `host-subcommand-groups.ts`) so * both paths are equally lazy. * * @throws {SystemError} When called outside a project scope — see * `buildDatastoreThunk`'s contract. */ export declare function getOrOpenDatastore(_log?: Logger): DataStore; /** * Project-scoped datastore accessor for the host-owned planes (baseline, * toolState, hostPlanes). Converts the internal DATASTORE_OUTSIDE_PROJECT * SystemError into a clear ConfigurationError so callers of the documented * ToolCliContext seams get a user-actionable error (exit 2) instead of an * internal SYSTEM.* code. * * @throws {ConfigurationError} When called outside a project scope (no open * datastore); other datastore-open failures propagate unchanged. */ export declare function getProjectDatastore(): DataStore; /** How a datastore resolver should behave when scope or project context is absent. */ export type DatastoreResolverMode = 'strict' | 'project-seam' | 'best-effort'; /** * Unified lazy datastore accessor for host planes and the run plane. * * - `strict` — throws when outside a project scope (via `getOrOpenDatastore`). * - `project-seam` — maps outside-project to `ConfigurationError` for documented seams. * - `best-effort` — returns `undefined` when scope or datastore is unavailable. */ export declare function createDatastoreResolver(mode: 'strict' | 'project-seam', logger?: Logger): () => DataStore; export declare function createDatastoreResolver(mode: 'best-effort', logger?: Logger): () => DataStore | undefined; //# sourceMappingURL=scope-access.d.ts.map