import { type ContextualCompilationResult, type Diagnostic, type WorkspaceSource } from '../compiler.js'; import { type EvidenceDocument } from '../evidence.js'; import { type CatalogueCompositionResult } from '../interrogate-command.js'; import type { Branding } from '../branding.js'; import type { SourceStore } from '../source-store.js'; import type { ResolvedWorkspace } from '../workspace-resolution.js'; /** * What every tool takes, and nothing else (ADR 0156). * * No path is ever passed: the store answers every read and takes every * write (ADR 0100), and the manifest arrives already resolved * (`resolveWorkspaceFrom` does that over a file list, no filesystem). The * paths inside `workspace` are store paths, the strings `store.read` * answers to: relative to the store's root, `/`-separated. A store rooted at * the repository root holds them as `.yarramate/architecture/...` with * `manifestDirectory: '.yarramate'`, which is how the CLI runs; a store * rooted at the `.yarramate` directory holds `architecture/...` with * `manifestDirectory: ''`. Both work; a record's own cross-references * (contracts, evidence URIs) are written relative to the repository root, * so a record that will ever be exported as a folder should use the first. */ export interface ToolWorkspace { /** list / read / writeAll. Synchronous, per ADR 0100. */ readonly store: SourceStore; /** The manifest, resolved. */ readonly workspace: ResolvedWorkspace; /** * Where the manifest sits relative to the store root, `/`-separated, no * trailing slash; `''` when the manifest is at the root. Lets an operation * address a document the way the manifest names it as well as the way the * workspace lists it (#216). Default `''`. */ readonly manifestDirectory?: string; /** * REPLACES the shipped base catalogue (`core-enrichment`), as `--catalogue` * does on the CLI. The catalogues the workspace itself lists under * `questions:` are read from the store and ADDED on top, always * (ADR 0129). Absent: the shipped catalogue, bundled as text. */ readonly catalogue?: WorkspaceSource; /** * Stamped into exports that carry a version (the workbook's provenance). * Default: the package's own version. */ readonly yarramateVersion?: string; /** * The host's branding (#546, ADR 0158): the workbook's cover sheet and the * LikeC4 banner name the product. Absent: the unbranded exports. */ readonly branding?: Branding; } /** * One shape for every tool that can fail. `diagnostics` is the engine * refusing with locations (a workspace that does not compile, an operations * batch with an invalid operation, a store conflict); `refused` is the tool * refusing an argument in one sentence (an unknown subject id, a projection * the store does not hold, a query that matches nothing). The CLI's exit 1 * and exit 2, respectively. `checkWorkspace` alone does not use this: a * failing check is its normal answer, not a failure. */ export type ToolResult = { readonly ok: true; readonly result: T; } | { readonly ok: false; readonly reason: 'diagnostics'; readonly diagnostics: readonly Diagnostic[]; } | { readonly ok: false; readonly reason: 'refused'; readonly message: string; }; export type ToolFailure = Exclude, { readonly ok: true; }>; export declare const failed: (diagnostics: readonly Diagnostic[]) => ToolFailure; export declare const refused: (message: string) => ToolFailure; /** The shipped base catalogue as a source. `path` is a label, not a file. */ export declare const SHIPPED_CATALOGUE: WorkspaceSource; /** * A store path the workspace lists but the store does not hold. Thrown by * the readers below and turned into a `refused` by the tool boundary * (`guarded`), the way the CLI turns a missing file into exit 2. */ export declare class MissingSourceError extends Error { readonly path: string; constructor(path: string); } export declare const readSource: ({ store }: ToolWorkspace, path: string) => WorkspaceSource; /** Every source the compiler is handed: profiles, patterns, documents, in that order. */ export declare const compilerSourcesOf: (workspace: ToolWorkspace) => readonly WorkspaceSource[]; export type Compiled = Extract; export declare const compileOf: (workspace: ToolWorkspace) => { readonly ok: true; readonly compiled: Compiled; } | ToolFailure; /** * The catalogues a verb composes: the base, then whatever the workspace * carries (#345, ADR 0129). One place, so every verb that interviews makes * the same choice. */ export declare const catalogueSourcesOf: (workspace: ToolWorkspace) => readonly WorkspaceSource[]; export declare const composedCatalogueOf: (workspace: ToolWorkspace, compiled: Compiled) => CatalogueCompositionResult; export declare const evidenceDocumentsOf: (workspace: ToolWorkspace) => { readonly ok: true; readonly documents: readonly EvidenceDocument[]; } | ToolFailure; /** * The tool boundary: a missing source becomes a `refused` rather than an * exception, and nothing else is caught, so a real defect still surfaces. */ export declare const guarded: (run: () => ToolResult) => ToolResult;