@hawkeyexl/manni 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -703,6 +703,14 @@ interface DerivedField {
703
703
  * reports it, when one does. `derive` writes there, never into the page.
704
704
  */
705
705
  manifest?: string;
706
+ /**
707
+ * Proposal 0047: the manifest a field other than `provenance` is written
708
+ * into, as the run reports it, when a manifest of the page's collections
709
+ * owns the key. Absent when the value goes to the page.
710
+ */
711
+ destination?: string;
712
+ /** The 1-based line of the key in `destination` after the write. Absent under `dryRun` and `check`. */
713
+ destinationLine?: number;
706
714
  }
707
715
  /**
708
716
  * The `schema` ref a stale-field finding carries, and so its baseline and
@@ -728,9 +736,14 @@ declare function compareDerived(field: DerivableField, asserted: unknown, derive
728
736
  * field that is `stale` or `unset`. Current and unknown fields file nothing.
729
737
  *
730
738
  * `lineFor` is the document's own pointer lookup, so a finding lands on the
731
- * line the asserted key sits on; an unset field has no line.
739
+ * line the asserted key sits on; an unset field has no line. `locate` answers
740
+ * for a value a manifest supplied (proposal 0047): the finding then names the
741
+ * manifest and its line, as every other manifest finding does.
732
742
  */
733
- declare function staleFindings(fields: readonly DerivedField[], lineFor: (pointer: string) => number | undefined): FieldError[];
743
+ declare function staleFindings(fields: readonly DerivedField[], lineFor: (pointer: string) => number | undefined, locate?: (pointer: string) => {
744
+ file: string;
745
+ line?: number;
746
+ } | undefined): FieldError[];
734
747
 
735
748
  interface SchemaOverride {
736
749
  /**
@@ -1367,183 +1380,205 @@ declare function runGet(opts: GetOptions): Promise<GetFileResult[]>;
1367
1380
  /** Ask a yes/no question; `true` only for a yes. */
1368
1381
  type Confirm = (question: string) => Promise<boolean>;
1369
1382
 
1370
- interface QueryOptions {
1371
- /**
1372
- * One SQL statement. The table is `docs`; see the system columns below.
1373
- * May be empty when `db` is set — export without querying.
1374
- */
1375
- sql: string;
1376
- /**
1377
- * `--db`: also write the built database to this file, for any SQLite
1378
- * front-end (sqlite3, Datasette, duckdb) to open afterwards. The file is a
1379
- * regenerated artifact: an existing SQLite file at the path is overwritten,
1380
- * anything else is refused.
1381
- */
1382
- db?: string;
1383
- inputs: string[];
1384
- as?: string;
1385
- exclude?: string[];
1386
- exts?: string[];
1387
- configPath?: string;
1388
- /** `--no-config`: skip config discovery and use the built-in defaults. */
1389
- noConfig?: boolean;
1390
- /**
1391
- * `--collection <name>`, repeatable: run over the named configured
1392
- * collections instead of every declared one (proposal 0041). Cannot be
1393
- * combined with positional paths; `-` is allowed beside it.
1394
- */
1395
- collections?: string[];
1396
- cwd?: string;
1397
- /** Content for the `-` (stdin) input, injected by the CLI/tests. */
1398
- stdinContent?: string;
1399
- /** Permit an input set that resolves to zero files (see `assertNonEmpty`). */
1400
- allowEmpty?: boolean;
1383
+ /**
1384
+ * The `schema` ref a collision finding carries, and so its baseline and rule
1385
+ * identity: `external:owned/external`. Shaped like `check:<name>` so
1386
+ * `classifyRef` passes it through as a built-in id rather than resolving it
1387
+ * as a cwd-relative file path, and reserved in the registry for the same
1388
+ * reason `check` is.
1389
+ */
1390
+ declare const EXTERNAL_OWNED_SCHEMA = "external:owned";
1391
+ /**
1392
+ * The `schema` ref of a duplicate-join finding (0039): two documents carry
1393
+ * the same value of a join field, so one manifest entry matched both.
1394
+ */
1395
+ declare const EXTERNAL_DUPLICATE_SCHEMA = "external:duplicate";
1396
+ /**
1397
+ * The `keyword` every external-metadata finding carries: no Ajv keyword
1398
+ * produced it.
1399
+ */
1400
+ declare const EXTERNAL_KEYWORD = "external";
1401
+ /** The join that names documents by path, and the default. */
1402
+ declare const PATH_JOIN = "path";
1403
+ /** One value a manifest supplied, and where it was written. */
1404
+ interface ExternalMetadataValue {
1405
+ value: unknown;
1406
+ /** The collection whose manifest supplied it (proposal 0041). */
1407
+ collection: string;
1408
+ /** Manifest path as the run reports it: relative to the run's base, posix — or the URL. */
1409
+ file: string;
1410
+ /** 1-based line of the key in the manifest, when known. */
1411
+ line?: number;
1401
1412
  /**
1402
- * `--no-gitignore` (false). Absent leaves config `respectGitignore:` in
1403
- * charge, which itself defaults to on.
1413
+ * 1-based manifest line of every node inside `value`, keyed by the JSON
1414
+ * Pointer relative to `value` (`/2/source/file`). A mapping member sits on
1415
+ * its key's line, and a list item on the line its node starts. Present only
1416
+ * when `value` is a mapping or a list with members; `line` answers for the
1417
+ * value itself.
1404
1418
  */
1405
- respectGitignore?: boolean;
1406
- /** Diagnostics for the user; the CLI writes these to stderr. */
1407
- onNotice?: (message: string) => void;
1408
- /** Called once when a config governs the run, so the CLI can report it. */
1409
- onConfigLoaded?: (info: ConfigNotice) => void;
1419
+ lines?: ReadonlyMap<string, number>;
1420
+ }
1421
+ /** One manifest entry, for the orphan checks. */
1422
+ interface ExternalMetadataEntry {
1423
+ /** The collection whose manifest declared it (proposal 0041). */
1424
+ collection: string;
1425
+ /** `path`, or the frontmatter field this entry is keyed by. */
1426
+ join: string;
1427
+ /** Absolute document path, for a path entry. */
1428
+ abs?: string;
1429
+ /** The key exactly as written in the manifest. */
1430
+ spelled: string;
1431
+ /** Manifest path as the run reports it. */
1432
+ file: string;
1433
+ /** 1-based line of the entry in the manifest, when known. */
1434
+ line?: number;
1435
+ }
1436
+ /** Every manifest of a run, loaded once and consulted per document. */
1437
+ interface ExternalMetadataIndex {
1410
1438
  /**
1411
- * `--offline`, accepted for surface parity with the other commands. DDL
1412
- * statements do resolve the corpus's schema set (0024), but only from disk
1413
- * and the bundled built-ins — a URL ref refuses with "vendor it first"
1414
- * before anything could fetch — so there is still no network dependency to
1415
- * suppress.
1439
+ * Owned key -> every collection that owns it, with the manifest that does.
1440
+ *
1441
+ * A list rather than one entry, because two collections may legitimately
1442
+ * each own the same key (0041 rule 5): `guides` and `blog` can both supply
1443
+ * `owner`. Ambiguity only exists for a file that is a member of both, which
1444
+ * is decided per file in `mergeExternalMetadata`.
1416
1445
  */
1446
+ owners: ReadonlyMap<string, readonly {
1447
+ collection: string;
1448
+ file: string;
1449
+ }[]>;
1450
+ /** Path-joined manifests: absolute document path -> owned key -> value. */
1451
+ byPath: ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>;
1452
+ /** Field-joined manifests: field -> value -> owned key -> value. */
1453
+ byField: ReadonlyMap<string, ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>>;
1454
+ /** Every manifest entry, in manifest order. */
1455
+ entries: readonly ExternalMetadataEntry[];
1456
+ }
1457
+ interface LoadExternalMetadataOptions {
1458
+ /** Directory `externalMetadata[].file` and every manifest key resolve from. */
1459
+ configDir: string;
1460
+ /** Directory the run's file labels are relative to; manifests are reported the same way. */
1461
+ base: string;
1462
+ /** `--offline` / `offline:`: a URL manifest is refused rather than fetched (0038). */
1417
1463
  offline?: boolean;
1464
+ /** Network timeout for a URL manifest; the schema fetch's default otherwise. */
1465
+ timeoutMs?: number;
1466
+ /** For tests: the environment `tokenEnv` is read from. */
1467
+ env?: Record<string, string | undefined>;
1468
+ }
1469
+ /** A place a merged value lives, for a finding that must name it. */
1470
+ interface SourceLocation {
1471
+ file: string;
1472
+ line?: number;
1473
+ col?: number;
1474
+ }
1475
+ /** A key the document carries that a manifest owns. */
1476
+ interface ExternalMetadataCollision {
1477
+ key: string;
1478
+ /** The owning manifest, as the run reports it. */
1479
+ file: string;
1480
+ /** The collection that manifest belongs to (proposal 0041). */
1481
+ collection: string;
1482
+ }
1483
+ /** A field-joined entry a document matched (0039). */
1484
+ interface ExternalMetadataJoin {
1485
+ field: string;
1486
+ /** The value matched: the field's plaintext, decrypted first when the page holds it encrypted. */
1487
+ value: string;
1418
1488
  /**
1419
- * `--no-cache` (false): ask GitHub or GitLab again rather than reading the
1420
- * review cache. Only a statement naming the `derived` table consults it,
1421
- * and only for `reviewed-by` and `last-reviewed`; absent leaves it on.
1422
- */
1423
- cache?: boolean;
1424
- /**
1425
- * `--dry-run`: preview the statement's per-file changes — the diff it
1426
- * would make, files untouched. Without it a mutating statement applies,
1427
- * matching `fill`'s convention (proposal 0025; 0022 recorded the original
1428
- * preview-by-default surface this revises).
1429
- */
1430
- dryRun?: boolean;
1431
- /**
1432
- * Values for the statement's named parameters (`$name`, `:name`, `@name`),
1433
- * keyed by bare name (a `$`/`:`/`@` prefix on a key is tolerated). Each
1434
- * value passes through the same `bindValue` the projection loader uses —
1435
- * booleans become 1/0, arrays and objects JSON text — so a bound parameter
1436
- * compares against a stored cell under exactly the encoding the cell got
1437
- * (proposal 0029). A parameter the SQL references with no entry here
1438
- * refuses: unbound would silently bind NULL and match nothing.
1439
- */
1440
- params?: Record<string, unknown>;
1441
- /**
1442
- * `-s/--schema`, repeatable: the schema set the run's DDL evolves — CLI
1443
- * precedence for the DDL planner *only* (proposal 0030). The per-file
1444
- * resolution walk is skipped and the deduped refs are the set; every guard
1445
- * inside the set (single local file for ADD, sole declarer for
1446
- * DROP/RENAME, builtin fork, URL refusal, the trust boundary) runs
1447
- * unchanged. Collection views keep following the config's resolution. A
1448
- * run whose statement produces no DDL effect refuses before anything is
1449
- * applied — a flag that would silently mean nothing must refuse.
1489
+ * The field as the page holds it, when that differs from `value`: the
1490
+ * ciphertext of an encrypted join field (proposal 0045). A finding about
1491
+ * the join names this, never the plaintext.
1450
1492
  */
1451
- schemas?: string[];
1493
+ pageValue?: string;
1494
+ /** The manifest, as the run reports it. */
1495
+ file: string;
1496
+ /** The collection that manifest belongs to (proposal 0041). */
1497
+ collection: string;
1498
+ }
1499
+ /** What `mergeExternalMetadata` hands back. */
1500
+ interface MergedMetadata {
1501
+ /** The document's metadata with every owned key the manifest supplied. */
1502
+ extracted: ExtractedMetadata;
1452
1503
  /**
1453
- * How to ask for a new encryption key when an `UPDATE` or `INSERT` writes
1454
- * a column its schema marks `x-manni-encrypt` and no key is available
1455
- * (proposal 0045). The CLI passes `terminalConfirm()`, which is
1456
- * `undefined` off a terminal; absent, such a write refuses (exit 2). A dry
1457
- * run never asks: it writes nothing.
1504
+ * Owned keys the document itself also carried, in document order, each
1505
+ * with the manifest that owns it — so the finding names it without a
1506
+ * second lookup, and without a fallback for an index that is not there.
1458
1507
  */
1459
- confirm?: Confirm;
1508
+ collisions: ExternalMetadataCollision[];
1509
+ /** Field-joined entries this document matched, one per manifest at most. */
1510
+ joins: ExternalMetadataJoin[];
1460
1511
  /**
1461
- * The environment `MANNI_ENCRYPTION_KEY` is read from. Defaults to
1462
- * `process.env`; tests pass their own.
1512
+ * Where a merged pointer's value lives. Answers only for a value the
1513
+ * manifest supplied — a bare key or its `/key` pointer, and anything
1514
+ * beneath it — and `undefined` for everything the document owns, which is
1515
+ * what `lineFor` is for.
1516
+ *
1517
+ * The line is the deepest manifest node the pointer reaches, so
1518
+ * `/citations/2` is the third item's line and `/citations/2/source/file`
1519
+ * that member's. A pointer past what the manifest holds falls back to the
1520
+ * nearest ancestor that exists, and at worst to the owned key's line.
1463
1521
  */
1464
- env?: NodeJS.ProcessEnv;
1465
- /** The clock an uncommitted body change is dated by. Test seam; default `new Date()`. */
1466
- now?: () => Date;
1522
+ locate: (pointer: string) => SourceLocation | undefined;
1467
1523
  }
1524
+ /** The join an external-metadata config asks for: `path` unless it names a field. */
1525
+ declare function externalMetadataJoin(manifest: Pick<ExternalMetadataConfig, "join">): string;
1468
1526
  /**
1469
- * One thing a statement changed, in file-space terms. Cell-level kinds carry
1470
- * a `key` (a set, a deletion via `SET k = NULL` / `ALTER DROP COLUMN`, or a
1471
- * key rename); file-level kinds carry the whole event (`cleared` — the block
1472
- * stripped by DELETE; `created` — a file INSERT made; `renamed` — a `_path`
1473
- * move). Exactly one kind per object.
1527
+ * Load every manifest of every collection the run covers. Resolves to `null`
1528
+ * when none of them declares one, which is every setup that existed before
1529
+ * this feature.
1530
+ *
1531
+ * Every refusal is a `DocmetaError`: the manifest is a config-supplied input,
1532
+ * and one that is missing or misshapen is the run's problem, not a
1533
+ * document's (0014).
1474
1534
  */
1475
- type QueryChange = {
1476
- file: string;
1477
- written: boolean;
1478
- } & ({
1479
- key: string;
1480
- from: unknown;
1481
- to: unknown;
1482
- } | {
1483
- key: string;
1484
- from: unknown;
1485
- deleted: true;
1486
- } | {
1487
- key: string;
1488
- renamedFrom: string;
1489
- to: unknown;
1490
- } | {
1491
- cleared: true;
1492
- from: Record<string, unknown>;
1493
- } | {
1494
- created: true;
1495
- to: Record<string, unknown>;
1496
- } | {
1497
- renamed: string;
1498
- } | {
1499
- /** A DDL statement edited the schema itself (0024): `file` is the
1500
- * schema written — an in-place edit, or the fork of a builtin. */
1501
- schema: true;
1502
- op: "add" | "drop" | "rename";
1503
- key: string;
1504
- renamedTo?: string;
1505
- type?: string;
1506
- /** 0028: a declared type equal to a format name carries the format. */
1507
- format?: string;
1508
- /** 0028: a `CHECK (k IN (…))` on the added column carries the enum. */
1509
- enum?: (string | number)[];
1510
- required?: boolean;
1511
- forkedFrom?: string;
1512
- } | {
1513
- /** A DDL side effect on the governing config file: a fork repoints the
1514
- * `schemas:` entry (`key: "schemas"`), an in-place edit of a pinned
1515
- * schema refreshes its pin (`key: "integrity"`). Disclosed as a change
1516
- * because the preview must name every file `--write` will touch. */
1517
- config: true;
1518
- key: string;
1519
- from: unknown;
1520
- to: unknown;
1521
- });
1522
- interface QueryRun {
1523
- /** Result column names, in SELECT order — present even for zero rows. */
1524
- columns: string[];
1525
- rows: Record<string, unknown>[];
1526
- /** Set when `db` was written: where, and how big the table is. */
1527
- db?: {
1528
- path: string;
1529
- files: number;
1530
- columns: number;
1531
- };
1532
- /**
1533
- * Present when the statement was a metadata edit: every cell it changed
1534
- * (empty when a mutating statement matched nothing). Absent on reads.
1535
- */
1536
- changes?: QueryChange[];
1537
- /**
1538
- * Where the run stood, in the same shape `ValidateRun.frame` carries — the
1539
- * path-normalization frame SARIF and JUnit need before they can name a file
1540
- * the way the repository does (proposal 0026). Constructed from the run's
1541
- * `cwd`, its config directory, and the directory file labels resolve
1542
- * against; absent only when a caller built a `QueryRun` by hand.
1543
- */
1544
- frame?: FingerprintContext;
1545
- }
1546
- declare function runQuery(opts: QueryOptions): Promise<QueryRun>;
1535
+ declare function loadExternalMetadata(collections: readonly CollectionConfig[], opts: LoadExternalMetadataOptions): Promise<ExternalMetadataIndex | null>;
1536
+ /**
1537
+ * Merge the external metadata for one document into its extracted metadata.
1538
+ *
1539
+ * `label` is the document as the run spells it, relative to `base`; a path
1540
+ * entry matches on the resolved absolute path, never on the spelling, so a
1541
+ * positional run from a subdirectory finds the same entry a config-corpus
1542
+ * run does. A field entry matches on the document's own value of the join
1543
+ * field, wherever the document lives. Stdin never matches a path entry:
1544
+ * there is no file behind it.
1545
+ *
1546
+ * `memberOf` names the collections this document belongs to, and only their
1547
+ * manifests are consulted (0041 rule 4). It is the caller's `memberOf(...)`
1548
+ * result, computed once per file.
1549
+ *
1550
+ * `present`, `format` and the document's own positions are untouched. A
1551
+ * manifest key is not in the document, so `lineFor` keeps answering
1552
+ * `undefined` for it, and `locate` answers instead.
1553
+ *
1554
+ * A join field the page holds encrypted (proposal 0045) is decrypted with
1555
+ * `options.encryptionKey` before it is matched. With no key, and a manifest
1556
+ * of this document's collections joining on that field, the run cannot match
1557
+ * and refuses. A ciphertext that does not decrypt matches nothing.
1558
+ */
1559
+ declare function mergeExternalMetadata(label: string, extracted: ExtractedMetadata, index: ExternalMetadataIndex | null, memberOf: readonly string[], base: string, options?: {
1560
+ encryptionKey?: () => string | undefined;
1561
+ }): MergedMetadata;
1562
+ /** The `/key` pointer for an external-metadata finding, RFC 6901 escaped. */
1563
+ declare function externalMetadataPointer(key: string): string;
1564
+ /**
1565
+ * Path entries naming no loaded document.
1566
+ *
1567
+ * `loaded` are the run's file labels, relative to `base`. Checked only when
1568
+ * the run is the config corpus (the same invariant corpus checks use): a
1569
+ * positional path means the operator chose to look at part of the corpus,
1570
+ * and an entry for the rest is expected, not orphaned.
1571
+ */
1572
+ declare function orphanEntries(index: ExternalMetadataIndex | null, loaded: readonly string[], base: string, collections?: readonly string[]): ExternalMetadataEntry[];
1573
+ /**
1574
+ * Field entries no loaded document matched (0039). `matched` is field -> the
1575
+ * values documents in the run carried, which the caller collects from each
1576
+ * document's `joins` — so this runs after the per-file loop, under the same
1577
+ * corpus invariant as `orphanEntries`.
1578
+ */
1579
+ declare function orphanJoins(index: ExternalMetadataIndex | null, matched: ReadonlyMap<string, ReadonlySet<string>>, collections?: readonly string[]): ExternalMetadataEntry[];
1580
+ /** The operational error an orphan check raises, naming the first entry. */
1581
+ declare function orphanError(orphans: readonly ExternalMetadataEntry[]): DocmetaError;
1547
1582
 
1548
1583
  interface BuiltinInfo {
1549
1584
  id: string;
@@ -1673,199 +1708,213 @@ declare function schemaLoadOptions(args: {
1673
1708
  /** Load and return the JSON Schema object for a reference. */
1674
1709
  declare function loadSchema(ref: string, options?: LoadSchemaOptions): Promise<Record<string, unknown>>;
1675
1710
 
1676
- interface SchemasInfo {
1677
- builtins: BuiltinInfo[];
1678
- formats: {
1679
- name: string;
1680
- extensions: string[];
1681
- implemented: boolean;
1682
- /** Whether `manni meta fill` can write metadata back to this format. */
1683
- writable: boolean;
1684
- }[];
1685
- }
1686
- declare function getSchemasInfo(): SchemasInfo;
1687
- /**
1688
- * Where a vendored schema lands by default.
1689
- *
1690
- * **Not** `.docmeta/`, which is gitignored wholesale and holds the schema and
1691
- * proposal caches. A vendored schema is the opposite kind of artifact: it has
1692
- * to be committed, because being in the consuming repository's own history is
1693
- * the entire point of vendoring.
1694
- */
1695
- declare const DEFAULT_VENDOR_DIR = "./schema";
1696
- interface VendorOptions {
1697
- /** The `http(s)` URL to download. */
1698
- url: string;
1699
- /** Directory for the vendored copy, relative to `cwd`. Default `./schema`. */
1700
- dir?: string;
1701
- /** `-c/--config`. Absent discovers a config, or creates one in `cwd`. */
1702
- configPath?: string;
1703
- cwd?: string;
1704
- /** Diagnostics for the user; the CLI writes these to stderr. */
1705
- onNotice?: (message: string) => void;
1706
- /** Fetch timeout, in ms. Defaults to the registry's. */
1707
- timeoutMs?: number;
1708
- /** Response size cap, in bytes. Defaults to the registry's. */
1709
- maxBytes?: number;
1710
- }
1711
- interface VendorResult {
1712
- /** The URL that was downloaded. */
1713
- url: string;
1714
- /** The vendored file, relative to `cwd`, posix-style. */
1715
- file: string;
1716
- /** The pin recorded for it. */
1717
- integrity: string;
1718
- /** Size of the vendored copy, in bytes. */
1719
- bytes: number;
1720
- /** The config that was written, relative to `cwd`, posix-style. */
1721
- config: string;
1722
- /** Whether that config had to be created. */
1723
- configCreated: boolean;
1724
- /** Whether an existing `schemas:` entry was replaced rather than appended. */
1725
- replaced: boolean;
1726
- /** Whether the downloaded bytes were identical to the copy already on disk. */
1727
- unchanged: boolean;
1728
- }
1729
1711
  /**
1730
- * The filename for a vendored schema, derived from the URL's last path segment.
1712
+ * `x-manni-location` (proposal 0047): where a schema would like a top-level
1713
+ * key's value stored, on the page or in external metadata.
1731
1714
  *
1732
- * Sanitized rather than trusted: the segment reaches the filesystem, so
1733
- * anything that is not an ordinary filename character is replaced, and a
1734
- * leading dot is prefixed away so the copy cannot land as a hidden file that
1735
- * directory walks skip.
1736
- */
1737
- declare function vendorFileName(url: string): string;
1738
- /**
1739
- * Download a remote schema into the repository and pin it.
1715
+ * The keyword is registered on every Ajv meta builds (validator.ts), next to
1716
+ * `x-manni-encrypt`, and like it records where it was evaluated. Ajv's own
1717
+ * resolution is the walker, so a mark counts through `$ref`, `allOf` and a
1718
+ * referenced built-in, and inside the `anyOf`, `oneOf` and `if`/`then`
1719
+ * branches Ajv takes. Only top-level properties carry a preference; a nested
1720
+ * mark is accepted and ignored. `Validator.locationPreferences` is the one
1721
+ * question commands ask of it.
1740
1722
  *
1741
- * The order of operations is the contract: everything that can refuse does so
1742
- * *before* the network call or the write, so a refused run leaves the working
1743
- * tree exactly as it found it.
1744
- */
1745
- declare function runVendorSchema(opts: VendorOptions): Promise<VendorResult>;
1746
-
1747
- /** Shared shapes for the `fill` command, split out to keep imports acyclic. */
1723
+ * One schema marking one key both ways is judged twice. Through `properties`,
1724
+ * `allOf` and local `$ref` alone, it is refused when the schema compiles.
1725
+ * Across conditional branches it is not an error: Ajv evaluates failing
1726
+ * branches too, so that schema gives the key no preference.
1727
+ */
1728
+ /** The schema keyword. */
1729
+ declare const LOCATION_KEYWORD = "x-manni-location";
1730
+ /** Where a top-level key prefers to live. */
1731
+ type FieldLocation = "page" | "external";
1732
+ /** A key's preferred location, and the schema ref whose mark decided it. */
1733
+ interface LocationPreference {
1734
+ location: FieldLocation;
1735
+ /** The ref, as given to `locationPreferences`, whose mark won. */
1736
+ schema: string;
1737
+ }
1748
1738
 
1749
- /** Why a proposed value was not written. */
1750
- type SkipReason =
1751
- /** Self-reported confidence was below the threshold. */
1752
- "low-confidence"
1753
- /** Writing it would leave the document failing its own schema. */
1754
- | "schema-mismatch"
1755
- /** The model declined to propose a value. */
1756
- | "no-proposal"
1757
- /**
1758
- * The field is managed by `derive` (`derive.fields` in the config), so it
1759
- * was never sent for inference: only `manni meta derive` writes it.
1760
- */
1761
- | "managed";
1762
- interface FilledField {
1763
- /** JSON Pointer, e.g. "/title" — the same form `validate` reports. */
1764
- field: string;
1765
- required: boolean;
1766
- confidence: number;
1767
- reasoning: string;
1739
+ declare class Validator {
1740
+ private readonly schemaOptions;
1768
1741
  /**
1769
- * Absent when the field was skipped. `(encrypted)` when the field's schema
1770
- * marks it `x-manni-encrypt`: the page holds the ciphertext, and no report
1771
- * prints either that or the plaintext (proposal 0045).
1742
+ * How this validator's schemas are loaded: the disk cache location, its TTL,
1743
+ * and `--offline`. Held per instance rather than read from module state, so
1744
+ * two differently-configured validations in one process each get their own
1745
+ * settings.
1746
+ *
1747
+ * That is not full isolation, and the difference matters to a library
1748
+ * caller: `schema-registry` keeps a process-wide memo of fetched schemas, so
1749
+ * one validator's successful fetch is visible to another. `offline` is
1750
+ * excluded from that sharing on purpose — an offline validator will not be
1751
+ * served something this process pulled over the network — but the memo is
1752
+ * still shared, so a URL fetched once is not re-fetched per instance.
1772
1753
  */
1773
- value?: unknown;
1774
- written: boolean;
1775
- skipReason?: SkipReason;
1754
+ constructor(schemaOptions?: LoadSchemaOptions);
1755
+ private ajvByDialect;
1776
1756
  /**
1777
- * The value was written encrypted, because the field's schema marks it
1778
- * `x-manni-encrypt`. Absent otherwise.
1757
+ * Keyed on the in-flight *promise*, not the resolved validator. Caching the
1758
+ * result made this a check-then-act race: `fill` walks files through a worker
1759
+ * pool, so every worker missed the cache while the first `loadSchema` was
1760
+ * still pending and they all then compiled the same schema into the one
1761
+ * shared per-dialect Ajv. Ajv registers a schema's `$id` on the first compile
1762
+ * and rejects the second with "schema with key or id ... already exists",
1763
+ * which took down any multi-file run against an $id-bearing schema. Storing
1764
+ * the promise before the first await lets the losers await the one compile.
1779
1765
  */
1780
- encrypted?: boolean;
1781
- }
1782
- /**
1783
- * One `meta-provenance` entry as `fill` writes it (proposal 0046): the model,
1784
- * the JSON Pointers of the fields it proposed, escaped per RFC 6901, and the
1785
- * confidence each was written at. Keys are the page's own spelling, so the
1786
- * JSON report shows exactly what landed in the document. An entry `fill`
1787
- * merged into keeps whatever else it held.
1788
- */
1789
- interface MetaProvenanceEntry {
1790
- "generated-by": string;
1791
- fields: string[];
1792
- confidence: Record<string, number>;
1793
- [other: string]: unknown;
1794
- }
1795
- /**
1796
- * What became of this file's `meta-provenance` entry. It is never a failure:
1797
- * neither outcome changes the summary or the exit code.
1798
- */
1799
- type MetaProvenanceReport = {
1800
- written: true;
1801
- entry: MetaProvenanceEntry;
1802
- }
1803
- /** The page's schemas, checked with the entry in place, reject it. */
1804
- | {
1805
- written: false;
1806
- skipReason: "schema-mismatch";
1807
- }
1808
- /** A manifest in one of the page's collections owns the key. */
1809
- | {
1810
- written: false;
1811
- skipReason: "manifest-owned";
1812
- manifest: string;
1813
- }
1814
- /**
1815
- * The format's writer cannot hold a list of entries (an HTML or XML
1816
- * attribute holds one line), so the fields were written without it.
1817
- */
1818
- | {
1819
- written: false;
1820
- skipReason: "unwritable";
1821
- };
1822
- interface FillFileResult {
1823
- file: string;
1824
- format: string;
1825
- schemas: string[];
1826
- fields: FilledField[];
1827
- /** Whether the file's content changed (false under --dry-run too). */
1828
- changed: boolean;
1829
- /** Parse failure, read-only format, or provider error. */
1830
- error?: string;
1831
- /** The filled document. Populated only when the caller asks for it. */
1832
- content?: string;
1766
+ private cache;
1767
+ private ajvFor;
1833
1768
  /**
1834
- * The `meta-provenance` entry recording the fields this run wrote
1835
- * (proposal 0046). Absent when no field was written; reported, not written,
1836
- * under `--dry-run`.
1769
+ * Synchronous by design: the `cache.set` has to happen in the same tick as
1770
+ * the miss, or a second caller can slip in before the entry exists.
1837
1771
  */
1838
- metaProvenance?: MetaProvenanceReport;
1772
+ private compile;
1773
+ private compileUncached;
1774
+ /**
1775
+ * The instance pointers of `data` that carry `x-manni-encrypt: true` under
1776
+ * any schema in `refs`, in the order the validator evaluated them.
1777
+ *
1778
+ * A first pass with the recording keyword, so a mark counts exactly where
1779
+ * validation would evaluate it. Only present values are marked: Ajv applies
1780
+ * a property's subschema to a property that exists. A branch Ajv does not
1781
+ * take (`then` behind a failing `if`, an `anyOf` branch after a passing
1782
+ * one) contributes nothing; a branch it takes contributes its marks
1783
+ * whether or not the branch passes, because a ciphertext routinely fails
1784
+ * the rest of its own subschema until it is decrypted.
1785
+ */
1786
+ markedPointers(data: Record<string, unknown>, refs: string[]): Promise<Set<string>>;
1787
+ /**
1788
+ * The location each top-level key of `data` prefers under `refs`: `page` or
1789
+ * `external`, and the ref whose `x-manni-location` mark decided it. A key no
1790
+ * schema marks has no entry.
1791
+ *
1792
+ * A first pass with the recording keyword, as `markedPointers` runs, so a
1793
+ * mark counts exactly where validation would evaluate it, and a nested mark
1794
+ * is ignored. Only present values are marked: Ajv applies a property's
1795
+ * subschema to a property that exists. A caller asking where a key it is
1796
+ * about to write belongs passes `data` that already holds the candidate
1797
+ * value. `$schema` is stripped first, as validation does.
1798
+ *
1799
+ * Refs are evaluated in order and a later ref's mark wins. A ref that says
1800
+ * both values for one key unconditionally is refused when it compiles; one
1801
+ * whose evaluated branches say both gives that key no preference.
1802
+ */
1803
+ locationPreferences(data: Record<string, unknown>, refs: string[]): Promise<Map<string, LocationPreference>>;
1804
+ /**
1805
+ * Validate `data` against every schema in `refs`. Returns all violations,
1806
+ * each tagged with the schema that produced it and a source line via
1807
+ * `lineFor`.
1808
+ *
1809
+ * `colFor` is optional and additive: this signature is public, so a fourth
1810
+ * *required* parameter — or a widened third one — would be a consumer break.
1811
+ * Callers with an extractor that supplies no column pass nothing and get the
1812
+ * previous behavior exactly.
1813
+ */
1814
+ validate(data: Record<string, unknown>, refs: string[], lineFor: (pointer: string) => number | undefined, colFor?: (pointer: string) => number | undefined,
1815
+ /**
1816
+ * Where a merged value lives when it is not in the document (proposal
1817
+ * 0037): a manifest's file and line. Consulted before `lineFor`,
1818
+ * and additive in the way `colFor` was.
1819
+ */
1820
+ locate?: (pointer: string) => SourceLocation | undefined): Promise<FieldError[]>;
1839
1821
  }
1840
- interface FillSummary {
1822
+
1823
+ /** Why a value was moved: its schema's mark, or a manifest that already owns the key. */
1824
+ type RelocateMoveReason = "preferred" | "owned";
1825
+ /** Why a value stayed on the side it is on. */
1826
+ type RelocateStayReason = "no-home" | "read-only-format" | "no-join-value" | "values-differ" | "url-manifest" | "unreadable";
1827
+ /** One value that moved, or would under `dryRun`. */
1828
+ type RelocateMove = {
1829
+ key: string;
1830
+ to: "page";
1831
+ from: string;
1832
+ reason: RelocateMoveReason;
1833
+ } | {
1834
+ key: string;
1835
+ to: "manifest";
1836
+ manifest: string;
1837
+ /** 1-based line of the key in the manifest afterwards. Absent under `dryRun`. */
1838
+ line?: number;
1839
+ reason: RelocateMoveReason;
1840
+ };
1841
+ /** One value that stayed on the wrong side. */
1842
+ interface RelocateStay {
1843
+ key: string;
1844
+ reason: RelocateStayReason;
1845
+ /** The sentence the pretty reporter prints after `stays: `. Not part of the JSON shape. */
1846
+ detail?: string;
1847
+ }
1848
+ interface RelocateFileResult {
1849
+ /** The page, as the run labels it. */
1850
+ file: string;
1851
+ moved: RelocateMove[];
1852
+ stayed: RelocateStay[];
1853
+ /** A member page outside the paths the run named, reached through a `keys:` or `paths:` change. */
1854
+ beyond: boolean;
1855
+ }
1856
+ interface RelocateManifestResult {
1857
+ /** The manifest as the run reports it: relative to the run's base, or the URL. */
1858
+ file: string;
1859
+ collection: string;
1860
+ /** Its index in the collection's `externalMetadata:` before the run. */
1861
+ index: number;
1862
+ created: boolean;
1863
+ keysAdded: string[];
1864
+ keysRemoved: string[];
1865
+ /** The keys it owns afterwards. */
1866
+ keys: string[];
1867
+ /** Whether its last key went, so the config no longer declares it (R3). */
1868
+ undeclared: boolean;
1869
+ /** Pages beyond the named paths whose values a `keys:` change moves, or leaves. */
1870
+ beyond: number;
1871
+ }
1872
+ interface RelocateConfigResult {
1873
+ /** The config file relative to the working directory, or null when there is none and none was needed. */
1874
+ file: string | null;
1875
+ created: boolean;
1876
+ collectionsCreated: {
1877
+ name: string;
1878
+ paths: string[];
1879
+ }[];
1880
+ pathsAdded: {
1881
+ collection: string;
1882
+ path: string;
1883
+ }[];
1884
+ }
1885
+ interface RelocateSummary {
1886
+ /** Pages with a value moved or stayed. */
1841
1887
  files: number;
1842
- changed: number;
1843
- written: number;
1844
- skipped: number;
1845
- /** Skipped fields that the schema lists as required — drives exit code 1. */
1846
- requiredSkipped: number;
1847
- errors: number;
1848
- costUsd: number;
1849
- cached: number;
1888
+ moved: number;
1889
+ stayed: number;
1890
+ manifestsCreated: number;
1850
1891
  }
1851
- interface FillRun {
1852
- results: FillFileResult[];
1853
- summary: FillSummary;
1854
- /** Echoed so JSON consumers and CI can assert which gate actually ran. */
1855
- threshold: number;
1892
+ interface RelocateResult {
1856
1893
  dryRun: boolean;
1857
- provider: string;
1858
- model: string;
1859
- /** True when the call cap stopped the run before every file was seen. */
1860
- turnsSpent: boolean;
1894
+ config: RelocateConfigResult;
1895
+ /** Every manifest the run creates, changes the keys of, or moves a value into or out of. */
1896
+ manifests: RelocateManifestResult[];
1897
+ files: RelocateFileResult[];
1898
+ summary: RelocateSummary;
1861
1899
  }
1862
- interface FillOptions {
1900
+
1901
+ interface QueryOptions {
1902
+ /**
1903
+ * One SQL statement. The table is `docs`; see the system columns below.
1904
+ * May be empty when `db` is set — export without querying.
1905
+ */
1906
+ sql: string;
1907
+ /**
1908
+ * `--db`: also write the built database to this file, for any SQLite
1909
+ * front-end (sqlite3, Datasette, duckdb) to open afterwards. The file is a
1910
+ * regenerated artifact: an existing SQLite file at the path is overwritten,
1911
+ * anything else is refused.
1912
+ */
1913
+ db?: string;
1863
1914
  inputs: string[];
1864
- cliSchemas?: string[];
1865
- exts?: string[];
1866
- exclude?: string[];
1867
- /** `--as` format override (extractor name). */
1868
1915
  as?: string;
1916
+ exclude?: string[];
1917
+ exts?: string[];
1869
1918
  configPath?: string;
1870
1919
  /** `--no-config`: skip config discovery and use the built-in defaults. */
1871
1920
  noConfig?: boolean;
@@ -1890,429 +1939,591 @@ interface FillOptions {
1890
1939
  /** Called once when a config governs the run, so the CLI can report it. */
1891
1940
  onConfigLoaded?: (info: ConfigNotice) => void;
1892
1941
  /**
1893
- * `--offline`: never fetch a remote **schema**. Absent leaves config
1894
- * `offline:` in charge.
1895
- *
1896
- * Scoped to schema loading only. It says nothing about the inference
1897
- * provider, which is a separate network dependency with its own controls
1898
- * (`--provider mock`, `--dry-run`).
1942
+ * `--offline`, accepted for surface parity with the other commands. DDL
1943
+ * statements do resolve the corpus's schema set (0024), but only from disk
1944
+ * and the bundled built-ins — a URL ref refuses with "vendor it first"
1945
+ * before anything could fetch — so there is still no network dependency to
1946
+ * suppress.
1899
1947
  */
1900
1948
  offline?: boolean;
1901
- /** Restrict proposals to these top-level fields. */
1902
- fields?: string[];
1903
- /** Minimum self-reported confidence to write (0-1). Default 0.7. */
1904
- confidence?: number;
1905
- /** Report proposals without writing them. */
1906
- dryRun?: boolean;
1907
- provider?: string;
1908
- model?: string;
1909
- /** Use the on-disk proposal cache. Default true. */
1910
- cache?: boolean;
1911
- /** Refuse a hosted provider: inference must run on this machine. */
1912
- local?: boolean;
1913
- /** Stop after this many inference calls. Counts calls, not files. */
1914
- maxTurns?: number;
1915
- /** Characters of document per call. Default 12000. */
1916
- chunkChars?: number;
1917
- /** Files inferred in parallel. Default 4. */
1918
- concurrency?: number;
1919
- /** Include the filled document on each result (used for stdin and tests). */
1920
- includeContent?: boolean;
1921
- /** Test seam: bypasses `makeProvider`, so no API key is needed. */
1922
- inferenceProvider?: InferenceProvider;
1923
1949
  /**
1924
- * How to ask for a new encryption key when a field its schema marks
1925
- * `x-manni-encrypt` is about to be written and no key is available
1926
- * (proposal 0045). The CLI passes `terminalConfirm()`, which is `undefined`
1927
- * off a terminal; absent, the run refuses (exit 2) before the first model
1928
- * request.
1950
+ * `--no-cache` (false): ask GitHub or GitLab again rather than reading the
1951
+ * review cache. Only a statement naming the `derived` table consults it,
1952
+ * and only for `reviewed-by` and `last-reviewed`; absent leaves it on.
1929
1953
  */
1930
- confirm?: Confirm;
1954
+ cache?: boolean;
1931
1955
  /**
1932
- * The environment `MANNI_ENCRYPTION_KEY` is read from. Defaults to
1933
- * `process.env`; tests pass their own.
1956
+ * `--dry-run`: preview the statement's per-file changes — the diff it
1957
+ * would make, files untouched. Without it a mutating statement applies,
1958
+ * matching `fill`'s convention (proposal 0025; 0022 recorded the original
1959
+ * preview-by-default surface this revises).
1934
1960
  */
1935
- env?: NodeJS.ProcessEnv;
1936
- }
1937
-
1938
- declare function runFill(opts: FillOptions): Promise<FillRun>;
1939
-
1940
- interface DeriveOptions {
1941
- inputs: string[];
1961
+ dryRun?: boolean;
1942
1962
  /**
1943
- * `--collection <name>`, repeatable: stamp only the named configured
1944
- * collections instead of every declared one (proposal 0041). Cannot be
1945
- * combined with paths.
1963
+ * Values for the statement's named parameters (`$name`, `:name`, `@name`),
1964
+ * keyed by bare name (a `$`/`:`/`@` prefix on a key is tolerated). Each
1965
+ * value passes through the same `bindValue` the projection loader uses —
1966
+ * booleans become 1/0, arrays and objects JSON text — so a bound parameter
1967
+ * compares against a stored cell under exactly the encoding the cell got
1968
+ * (proposal 0029). A parameter the SQL references with no entry here
1969
+ * refuses: unbound would silently bind NULL and match nothing.
1946
1970
  */
1947
- collections?: string[];
1948
- /** `--fields`: the managed fields to stamp this run; config `derive.fields` otherwise. */
1949
- fields?: string[];
1950
- /** `--sources`: the sources to consult; config `derive.sources`, else all four. */
1951
- sources?: string[];
1952
- /** `--dry-run`: report what would change and write nothing. */
1953
- dryRun?: boolean;
1954
- /** `--check`: implies `dryRun`; stale and unset fields are findings. */
1955
- check?: boolean;
1956
- /** Use the on-disk GitHub or GitLab review cache. Default true. */
1957
- cache?: boolean;
1958
- /** `--as` format override (extractor name). */
1959
- as?: string;
1960
- exts?: string[];
1961
- exclude?: string[];
1962
- configPath?: string;
1963
- /** `--no-config`: skip config discovery and use the built-in defaults. */
1964
- noConfig?: boolean;
1965
- cwd?: string;
1966
- /** Permit an input set that resolves to zero files (see `assertNonEmpty`). */
1967
- allowEmpty?: boolean;
1971
+ params?: Record<string, unknown>;
1968
1972
  /**
1969
- * `--no-gitignore` (false). Absent leaves config `respectGitignore:` in
1970
- * charge, which itself defaults to on.
1973
+ * `-s/--schema`, repeatable: the schema set the run's DDL evolves — CLI
1974
+ * precedence for the DDL planner *only* (proposal 0030). The per-file
1975
+ * resolution walk is skipped and the deduped refs are the set; every guard
1976
+ * inside the set (single local file for ADD, sole declarer for
1977
+ * DROP/RENAME, builtin fork, URL refusal, the trust boundary) runs
1978
+ * unchanged. Collection views keep following the config's resolution. A
1979
+ * run whose statement produces no DDL effect refuses before anything is
1980
+ * applied — a flag that would silently mean nothing must refuse.
1971
1981
  */
1972
- respectGitignore?: boolean;
1973
- /** Diagnostics for the user; the CLI writes these to stderr. */
1974
- onNotice?: (message: string) => void;
1975
- /** Called once when a config governs the run, so the CLI can report it. */
1976
- onConfigLoaded?: (info: ConfigNotice) => void;
1977
- /** The clock an uncommitted body change is dated by. Test seam; default `new Date()`. */
1978
- now?: () => Date;
1979
- /** The review client, for every repository in the run. Test seam; default `gh` / `glab`. */
1980
- reviews?: ReviewClient;
1982
+ schemas?: string[];
1981
1983
  /**
1982
- * How to ask for a new encryption key when a field its schema marks
1983
- * `x-manni-encrypt` is about to be stamped and no key is available
1984
- * (proposal 0045). The CLI passes `terminalConfirm()`, which is `undefined`
1985
- * off a terminal; absent, such a stamp refuses (exit 2). A dry run never
1986
- * asks: it writes nothing.
1984
+ * How to ask for a new encryption key when an `UPDATE` or `INSERT` writes
1985
+ * a column its schema marks `x-manni-encrypt` and no key is available
1986
+ * (proposal 0045). The CLI passes `terminalConfirm()`, which is
1987
+ * `undefined` off a terminal; absent, such a write refuses (exit 2). A dry
1988
+ * run never asks: it writes nothing.
1987
1989
  */
1988
1990
  confirm?: Confirm;
1991
+ /**
1992
+ * Called with relocate's result when a write's P1 offer was accepted and
1993
+ * the values moved (proposal 0047), so the CLI can print relocate's report.
1994
+ */
1995
+ onRelocated?: (result: RelocateResult) => void;
1989
1996
  /**
1990
1997
  * The environment `MANNI_ENCRYPTION_KEY` is read from. Defaults to
1991
1998
  * `process.env`; tests pass their own.
1992
1999
  */
1993
2000
  env?: NodeJS.ProcessEnv;
1994
- /**
1995
- * `--generated-by <name>` (proposal 0046): the machine uncommitted body
1996
- * lines go to, or the lines a `<path>:L1-L2` positional names. Absent reads
1997
- * `MANNI_GENERATED_BY` from `env`; an empty value is unset either way.
1998
- */
1999
- generatedBy?: string;
2001
+ /** The clock an uncommitted body change is dated by. Test seam; default `new Date()`. */
2002
+ now?: () => Date;
2000
2003
  }
2001
- interface DeriveFileResult {
2002
- file: string;
2003
- /** Extractor/format used; `unknown` when none matched the file. */
2004
- format: string;
2005
- /** One entry per requested field, in the requested order. Empty on `error`. */
2006
- fields: DerivedField[];
2007
- /**
2008
- * Whether writing the stale and unset fields changed the document, or
2009
- * would have but for `dryRun`. Computed from the writer's output, so a
2010
- * patch the format serializes to the same bytes is not a change.
2011
- */
2012
- changed: boolean;
2013
- /** Why the file could not be derived or written; the run goes on without it. */
2014
- error?: string;
2004
+ /**
2005
+ * One thing a statement changed, in file-space terms. Cell-level kinds carry
2006
+ * a `key` (a set, a deletion via `SET k = NULL` / `ALTER DROP COLUMN`, or a
2007
+ * key rename); file-level kinds carry the whole event (`cleared` — the block
2008
+ * stripped by DELETE; `created` — a file INSERT made; `renamed` — a `_path`
2009
+ * move). Exactly one kind per object.
2010
+ *
2011
+ * `manifest` (proposal 0047) names the external-metadata manifest the change
2012
+ * lands in, as the run reports it, when it lands in one: an owned key's set,
2013
+ * removal or rename, a created file's owned keys, a stripped document's
2014
+ * entry, or a moved document's entry.
2015
+ */
2016
+ type QueryChange = {
2017
+ file: string;
2018
+ written: boolean;
2019
+ manifest?: string;
2020
+ } & ({
2021
+ key: string;
2022
+ from: unknown;
2023
+ to: unknown;
2024
+ } | {
2025
+ key: string;
2026
+ from: unknown;
2027
+ deleted: true;
2028
+ } | {
2029
+ key: string;
2030
+ renamedFrom: string;
2031
+ to: unknown;
2032
+ } | {
2033
+ cleared: true;
2034
+ from: Record<string, unknown>;
2035
+ } | {
2036
+ created: true;
2037
+ to: Record<string, unknown>;
2038
+ } | {
2039
+ renamed: string;
2040
+ } | {
2041
+ /** A DDL statement edited the schema itself (0024): `file` is the
2042
+ * schema written — an in-place edit, or the fork of a builtin. */
2043
+ schema: true;
2044
+ op: "add" | "drop" | "rename";
2045
+ key: string;
2046
+ renamedTo?: string;
2047
+ type?: string;
2048
+ /** 0028: a declared type equal to a format name carries the format. */
2049
+ format?: string;
2050
+ /** 0028: a `CHECK (k IN (…))` on the added column carries the enum. */
2051
+ enum?: (string | number)[];
2052
+ required?: boolean;
2053
+ forkedFrom?: string;
2054
+ } | {
2055
+ /** A DDL side effect on the governing config file: a fork repoints the
2056
+ * `schemas:` entry (`key: "schemas"`), an in-place edit of a pinned
2057
+ * schema refreshes its pin (`key: "integrity"`). Disclosed as a change
2058
+ * because the preview must name every file `--write` will touch. */
2059
+ config: true;
2060
+ key: string;
2061
+ from: unknown;
2062
+ to: unknown;
2063
+ });
2064
+ interface QueryRun {
2065
+ /** Result column names, in SELECT order — present even for zero rows. */
2066
+ columns: string[];
2067
+ rows: Record<string, unknown>[];
2068
+ /** Set when `db` was written: where, and how big the table is. */
2069
+ db?: {
2070
+ path: string;
2071
+ files: number;
2072
+ columns: number;
2073
+ };
2015
2074
  /**
2016
- * Under `check`, the findings for this file: one per stale or unset field,
2017
- * at the field's line, plus one for an `error`. Absent otherwise.
2075
+ * Present when the statement was a metadata edit: every cell it changed
2076
+ * (empty when a mutating statement matched nothing). Absent on reads.
2018
2077
  */
2019
- findings?: FieldError[];
2020
- }
2021
- interface DeriveSummary {
2022
- files: number;
2023
- /** Files whose document changed, or would have under `dryRun`. */
2024
- changed: number;
2025
- /** Fields whose write reached the disk: always 0 under `dryRun` and `check`. */
2026
- written: number;
2078
+ changes?: QueryChange[];
2027
2079
  /**
2028
- * `provenance` ranges whose write reached the disk (proposal 0046): always
2029
- * 0 under `dryRun` and `check`. Present only when the run derives
2030
- * `provenance`.
2080
+ * Where the run stood, in the same shape `ValidateRun.frame` carries — the
2081
+ * path-normalization frame SARIF and JUnit need before they can name a file
2082
+ * the way the repository does (proposal 0026). Constructed from the run's
2083
+ * `cwd`, its config directory, and the directory file labels resolve
2084
+ * against; absent only when a caller built a `QueryRun` by hand.
2031
2085
  */
2032
- ranges?: number;
2033
- stale: number;
2034
- unset: number;
2035
- unknown: number;
2036
- errors: number;
2037
- }
2038
- interface DeriveRun {
2039
- results: DeriveFileResult[];
2040
- summary: DeriveSummary;
2041
- dryRun: boolean;
2042
- check: boolean;
2043
- /** One status per source the run consulted; a source nobody asked for is absent. */
2044
- sources: Partial<Record<DeriveSource, SourceStatus$1>>;
2045
- /** Where the run stood, for the SARIF reporter under `check`. See `ValidateRun.frame`. */
2046
- frame: FingerprintContext;
2086
+ frame?: FingerprintContext;
2047
2087
  }
2048
- declare function runDerive(opts: DeriveOptions): Promise<DeriveRun>;
2088
+ declare function runQuery(opts: QueryOptions): Promise<QueryRun>;
2049
2089
 
2090
+ interface SchemasInfo {
2091
+ builtins: BuiltinInfo[];
2092
+ formats: {
2093
+ name: string;
2094
+ extensions: string[];
2095
+ implemented: boolean;
2096
+ /** Whether `manni meta fill` can write metadata back to this format. */
2097
+ writable: boolean;
2098
+ }[];
2099
+ }
2100
+ declare function getSchemasInfo(): SchemasInfo;
2050
2101
  /**
2051
- * The `schema` ref a collision finding carries, and so its baseline and rule
2052
- * identity: `external:owned/external`. Shaped like `check:<name>` so
2053
- * `classifyRef` passes it through as a built-in id rather than resolving it
2054
- * as a cwd-relative file path, and reserved in the registry for the same
2055
- * reason `check` is.
2102
+ * Where a vendored schema lands by default.
2103
+ *
2104
+ * **Not** `.docmeta/`, which is gitignored wholesale and holds the schema and
2105
+ * proposal caches. A vendored schema is the opposite kind of artifact: it has
2106
+ * to be committed, because being in the consuming repository's own history is
2107
+ * the entire point of vendoring.
2056
2108
  */
2057
- declare const EXTERNAL_OWNED_SCHEMA = "external:owned";
2109
+ declare const DEFAULT_VENDOR_DIR = "./schema";
2110
+ interface VendorOptions {
2111
+ /** The `http(s)` URL to download. */
2112
+ url: string;
2113
+ /** Directory for the vendored copy, relative to `cwd`. Default `./schema`. */
2114
+ dir?: string;
2115
+ /** `-c/--config`. Absent discovers a config, or creates one in `cwd`. */
2116
+ configPath?: string;
2117
+ cwd?: string;
2118
+ /** Diagnostics for the user; the CLI writes these to stderr. */
2119
+ onNotice?: (message: string) => void;
2120
+ /** Fetch timeout, in ms. Defaults to the registry's. */
2121
+ timeoutMs?: number;
2122
+ /** Response size cap, in bytes. Defaults to the registry's. */
2123
+ maxBytes?: number;
2124
+ }
2125
+ interface VendorResult {
2126
+ /** The URL that was downloaded. */
2127
+ url: string;
2128
+ /** The vendored file, relative to `cwd`, posix-style. */
2129
+ file: string;
2130
+ /** The pin recorded for it. */
2131
+ integrity: string;
2132
+ /** Size of the vendored copy, in bytes. */
2133
+ bytes: number;
2134
+ /** The config that was written, relative to `cwd`, posix-style. */
2135
+ config: string;
2136
+ /** Whether that config had to be created. */
2137
+ configCreated: boolean;
2138
+ /** Whether an existing `schemas:` entry was replaced rather than appended. */
2139
+ replaced: boolean;
2140
+ /** Whether the downloaded bytes were identical to the copy already on disk. */
2141
+ unchanged: boolean;
2142
+ }
2058
2143
  /**
2059
- * The `schema` ref of a duplicate-join finding (0039): two documents carry
2060
- * the same value of a join field, so one manifest entry matched both.
2144
+ * The filename for a vendored schema, derived from the URL's last path segment.
2145
+ *
2146
+ * Sanitized rather than trusted: the segment reaches the filesystem, so
2147
+ * anything that is not an ordinary filename character is replaced, and a
2148
+ * leading dot is prefixed away so the copy cannot land as a hidden file that
2149
+ * directory walks skip.
2061
2150
  */
2062
- declare const EXTERNAL_DUPLICATE_SCHEMA = "external:duplicate";
2151
+ declare function vendorFileName(url: string): string;
2063
2152
  /**
2064
- * The `keyword` every external-metadata finding carries: no Ajv keyword
2065
- * produced it.
2153
+ * Download a remote schema into the repository and pin it.
2154
+ *
2155
+ * The order of operations is the contract: everything that can refuse does so
2156
+ * *before* the network call or the write, so a refused run leaves the working
2157
+ * tree exactly as it found it.
2066
2158
  */
2067
- declare const EXTERNAL_KEYWORD = "external";
2068
- /** The join that names documents by path, and the default. */
2069
- declare const PATH_JOIN = "path";
2070
- /** One value a manifest supplied, and where it was written. */
2071
- interface ExternalMetadataValue {
2072
- value: unknown;
2073
- /** The collection whose manifest supplied it (proposal 0041). */
2074
- collection: string;
2075
- /** Manifest path as the run reports it: relative to the run's base, posix — or the URL. */
2076
- file: string;
2077
- /** 1-based line of the key in the manifest, when known. */
2078
- line?: number;
2159
+ declare function runVendorSchema(opts: VendorOptions): Promise<VendorResult>;
2160
+
2161
+ /** Shared shapes for the `fill` command, split out to keep imports acyclic. */
2162
+
2163
+ /** Why a proposed value was not written. */
2164
+ type SkipReason =
2165
+ /** Self-reported confidence was below the threshold. */
2166
+ "low-confidence"
2167
+ /** Writing it would leave the document failing its own schema. */
2168
+ | "schema-mismatch"
2169
+ /** The model declined to propose a value. */
2170
+ | "no-proposal"
2171
+ /**
2172
+ * The field is managed by `derive` (`derive.fields` in the config), so it
2173
+ * was never sent for inference: only `manni meta derive` writes it.
2174
+ */
2175
+ | "managed";
2176
+ interface FilledField {
2177
+ /** JSON Pointer, e.g. "/title" — the same form `validate` reports. */
2178
+ field: string;
2179
+ required: boolean;
2180
+ confidence: number;
2181
+ reasoning: string;
2079
2182
  /**
2080
- * 1-based manifest line of every node inside `value`, keyed by the JSON
2081
- * Pointer relative to `value` (`/2/source/file`). A mapping member sits on
2082
- * its key's line, and a list item on the line its node starts. Present only
2083
- * when `value` is a mapping or a list with members; `line` answers for the
2084
- * value itself.
2183
+ * Absent when the field was skipped. `(encrypted)` when the field's schema
2184
+ * marks it `x-manni-encrypt`: the page holds the ciphertext, and no report
2185
+ * prints either that or the plaintext (proposal 0045).
2085
2186
  */
2086
- lines?: ReadonlyMap<string, number>;
2087
- }
2088
- /** One manifest entry, for the orphan checks. */
2089
- interface ExternalMetadataEntry {
2090
- /** The collection whose manifest declared it (proposal 0041). */
2091
- collection: string;
2092
- /** `path`, or the frontmatter field this entry is keyed by. */
2093
- join: string;
2094
- /** Absolute document path, for a path entry. */
2095
- abs?: string;
2096
- /** The key exactly as written in the manifest. */
2097
- spelled: string;
2098
- /** Manifest path as the run reports it. */
2099
- file: string;
2100
- /** 1-based line of the entry in the manifest, when known. */
2101
- line?: number;
2102
- }
2103
- /** Every manifest of a run, loaded once and consulted per document. */
2104
- interface ExternalMetadataIndex {
2187
+ value?: unknown;
2188
+ written: boolean;
2189
+ skipReason?: SkipReason;
2105
2190
  /**
2106
- * Owned key -> every collection that owns it, with the manifest that does.
2107
- *
2108
- * A list rather than one entry, because two collections may legitimately
2109
- * each own the same key (0041 rule 5): `guides` and `blog` can both supply
2110
- * `owner`. Ambiguity only exists for a file that is a member of both, which
2111
- * is decided per file in `mergeExternalMetadata`.
2191
+ * The value was written encrypted, because the field's schema marks it
2192
+ * `x-manni-encrypt`. Absent otherwise.
2112
2193
  */
2113
- owners: ReadonlyMap<string, readonly {
2114
- collection: string;
2115
- file: string;
2116
- }[]>;
2117
- /** Path-joined manifests: absolute document path -> owned key -> value. */
2118
- byPath: ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>;
2119
- /** Field-joined manifests: field -> value -> owned key -> value. */
2120
- byField: ReadonlyMap<string, ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>>;
2121
- /** Every manifest entry, in manifest order. */
2122
- entries: readonly ExternalMetadataEntry[];
2194
+ encrypted?: boolean;
2195
+ /**
2196
+ * Proposal 0047: the manifest the value was written into, as the run
2197
+ * reports it, when a manifest of the page's collections owns the key.
2198
+ * Absent when the value went to the page.
2199
+ */
2200
+ destination?: string;
2123
2201
  }
2124
- interface LoadExternalMetadataOptions {
2125
- /** Directory `externalMetadata[].file` and every manifest key resolve from. */
2126
- configDir: string;
2127
- /** Directory the run's file labels are relative to; manifests are reported the same way. */
2128
- base: string;
2129
- /** `--offline` / `offline:`: a URL manifest is refused rather than fetched (0038). */
2130
- offline?: boolean;
2131
- /** Network timeout for a URL manifest; the schema fetch's default otherwise. */
2132
- timeoutMs?: number;
2133
- /** For tests: the environment `tokenEnv` is read from. */
2134
- env?: Record<string, string | undefined>;
2202
+ /**
2203
+ * One `meta-provenance` entry as `fill` writes it (proposal 0046): the model,
2204
+ * the JSON Pointers of the fields it proposed, escaped per RFC 6901, and the
2205
+ * confidence each was written at. Keys are the page's own spelling, so the
2206
+ * JSON report shows exactly what landed in the document. An entry `fill`
2207
+ * merged into keeps whatever else it held.
2208
+ */
2209
+ interface MetaProvenanceEntry {
2210
+ "generated-by": string;
2211
+ fields: string[];
2212
+ confidence: Record<string, number>;
2213
+ [other: string]: unknown;
2135
2214
  }
2136
- /** A place a merged value lives, for a finding that must name it. */
2137
- interface SourceLocation {
2138
- file: string;
2139
- line?: number;
2140
- col?: number;
2215
+ /**
2216
+ * What became of this file's `meta-provenance` entry. It is never a failure:
2217
+ * neither outcome changes the summary or the exit code.
2218
+ */
2219
+ type MetaProvenanceReport = {
2220
+ written: true;
2221
+ entry: MetaProvenanceEntry;
2222
+ /** The manifest the entry was written into, when one owns `meta-provenance` (0047). */
2223
+ destination?: string;
2141
2224
  }
2142
- /** A key the document carries that a manifest owns. */
2143
- interface ExternalMetadataCollision {
2144
- key: string;
2145
- /** The owning manifest, as the run reports it. */
2146
- file: string;
2147
- /** The collection that manifest belongs to (proposal 0041). */
2148
- collection: string;
2225
+ /** The page's schemas, checked with the entry in place, reject it. */
2226
+ | {
2227
+ written: false;
2228
+ skipReason: "schema-mismatch";
2149
2229
  }
2150
- /** A field-joined entry a document matched (0039). */
2151
- interface ExternalMetadataJoin {
2152
- field: string;
2153
- /** The value matched: the field's plaintext, decrypted first when the page holds it encrypted. */
2154
- value: string;
2230
+ /** A URL manifest in one of the page's collections owns the key, and cannot be written (0047). */
2231
+ | {
2232
+ written: false;
2233
+ skipReason: "manifest-owned";
2234
+ manifest: string;
2235
+ }
2236
+ /**
2237
+ * The format's writer cannot hold a list of entries (an HTML or XML
2238
+ * attribute holds one line), so the fields were written without it.
2239
+ */
2240
+ | {
2241
+ written: false;
2242
+ skipReason: "unwritable";
2243
+ };
2244
+ interface FillFileResult {
2245
+ file: string;
2246
+ format: string;
2247
+ schemas: string[];
2248
+ fields: FilledField[];
2249
+ /** Whether the file's content changed (false under --dry-run too). */
2250
+ changed: boolean;
2251
+ /** Parse failure, read-only format, or provider error. */
2252
+ error?: string;
2253
+ /** The filled document. Populated only when the caller asks for it. */
2254
+ content?: string;
2155
2255
  /**
2156
- * The field as the page holds it, when that differs from `value`: the
2157
- * ciphertext of an encrypted join field (proposal 0045). A finding about
2158
- * the join names this, never the plaintext.
2256
+ * The `meta-provenance` entry recording the fields this run wrote
2257
+ * (proposal 0046). Absent when no field was written; reported, not written,
2258
+ * under `--dry-run`.
2159
2259
  */
2160
- pageValue?: string;
2161
- /** The manifest, as the run reports it. */
2162
- file: string;
2163
- /** The collection that manifest belongs to (proposal 0041). */
2164
- collection: string;
2260
+ metaProvenance?: MetaProvenanceReport;
2165
2261
  }
2166
- /** What `mergeExternalMetadata` hands back. */
2167
- interface MergedMetadata {
2168
- /** The document's metadata with every owned key the manifest supplied. */
2169
- extracted: ExtractedMetadata;
2262
+ interface FillSummary {
2263
+ files: number;
2264
+ changed: number;
2265
+ written: number;
2266
+ skipped: number;
2267
+ /** Skipped fields that the schema lists as required — drives exit code 1. */
2268
+ requiredSkipped: number;
2269
+ errors: number;
2270
+ costUsd: number;
2271
+ cached: number;
2272
+ }
2273
+ interface FillRun {
2274
+ results: FillFileResult[];
2275
+ summary: FillSummary;
2276
+ /** Echoed so JSON consumers and CI can assert which gate actually ran. */
2277
+ threshold: number;
2278
+ dryRun: boolean;
2279
+ provider: string;
2280
+ model: string;
2281
+ /** True when the call cap stopped the run before every file was seen. */
2282
+ turnsSpent: boolean;
2283
+ }
2284
+ interface FillOptions {
2285
+ inputs: string[];
2286
+ cliSchemas?: string[];
2287
+ exts?: string[];
2288
+ exclude?: string[];
2289
+ /** `--as` format override (extractor name). */
2290
+ as?: string;
2291
+ configPath?: string;
2292
+ /** `--no-config`: skip config discovery and use the built-in defaults. */
2293
+ noConfig?: boolean;
2294
+ /**
2295
+ * `--collection <name>`, repeatable: run over the named configured
2296
+ * collections instead of every declared one (proposal 0041). Cannot be
2297
+ * combined with positional paths; `-` is allowed beside it.
2298
+ */
2299
+ collections?: string[];
2300
+ cwd?: string;
2301
+ /** Content for the `-` (stdin) input, injected by the CLI/tests. */
2302
+ stdinContent?: string;
2303
+ /** Permit an input set that resolves to zero files (see `assertNonEmpty`). */
2304
+ allowEmpty?: boolean;
2305
+ /**
2306
+ * `--no-gitignore` (false). Absent leaves config `respectGitignore:` in
2307
+ * charge, which itself defaults to on.
2308
+ */
2309
+ respectGitignore?: boolean;
2310
+ /** Diagnostics for the user; the CLI writes these to stderr. */
2311
+ onNotice?: (message: string) => void;
2312
+ /** Called once when a config governs the run, so the CLI can report it. */
2313
+ onConfigLoaded?: (info: ConfigNotice) => void;
2314
+ /**
2315
+ * `--offline`: never fetch a remote **schema**. Absent leaves config
2316
+ * `offline:` in charge.
2317
+ *
2318
+ * Scoped to schema loading only. It says nothing about the inference
2319
+ * provider, which is a separate network dependency with its own controls
2320
+ * (`--provider mock`, `--dry-run`).
2321
+ */
2322
+ offline?: boolean;
2323
+ /** Restrict proposals to these top-level fields. */
2324
+ fields?: string[];
2325
+ /** Minimum self-reported confidence to write (0-1). Default 0.7. */
2326
+ confidence?: number;
2327
+ /** Report proposals without writing them. */
2328
+ dryRun?: boolean;
2329
+ provider?: string;
2330
+ model?: string;
2331
+ /** Use the on-disk proposal cache. Default true. */
2332
+ cache?: boolean;
2333
+ /** Refuse a hosted provider: inference must run on this machine. */
2334
+ local?: boolean;
2335
+ /** Stop after this many inference calls. Counts calls, not files. */
2336
+ maxTurns?: number;
2337
+ /** Characters of document per call. Default 12000. */
2338
+ chunkChars?: number;
2339
+ /** Files inferred in parallel. Default 4. */
2340
+ concurrency?: number;
2341
+ /** Include the filled document on each result (used for stdin and tests). */
2342
+ includeContent?: boolean;
2343
+ /** Test seam: bypasses `makeProvider`, so no API key is needed. */
2344
+ inferenceProvider?: InferenceProvider;
2345
+ /**
2346
+ * How to ask for a new encryption key when a field its schema marks
2347
+ * `x-manni-encrypt` is about to be written and no key is available
2348
+ * (proposal 0045). The CLI passes `terminalConfirm()`, which is `undefined`
2349
+ * off a terminal; absent, the run refuses (exit 2) before the first model
2350
+ * request.
2351
+ */
2352
+ confirm?: Confirm;
2170
2353
  /**
2171
- * Owned keys the document itself also carried, in document order, each
2172
- * with the manifest that owns it — so the finding names it without a
2173
- * second lookup, and without a fallback for an index that is not there.
2354
+ * The environment `MANNI_ENCRYPTION_KEY` is read from. Defaults to
2355
+ * `process.env`; tests pass their own.
2174
2356
  */
2175
- collisions: ExternalMetadataCollision[];
2176
- /** Field-joined entries this document matched, one per manifest at most. */
2177
- joins: ExternalMetadataJoin[];
2357
+ env?: NodeJS.ProcessEnv;
2178
2358
  /**
2179
- * Where a merged pointer's value lives. Answers only for a value the
2180
- * manifest supplied — a bare key or its `/key` pointer, and anything
2181
- * beneath it — and `undefined` for everything the document owns, which is
2182
- * what `lineFor` is for.
2183
- *
2184
- * The line is the deepest manifest node the pointer reaches, so
2185
- * `/citations/2` is the third item's line and `/citations/2/source/file`
2186
- * that member's. A pointer past what the manifest holds falls back to the
2187
- * nearest ancestor that exists, and at worst to the owned key's line.
2359
+ * Called with relocate's result after the user accepts a P1 offer
2360
+ * (proposal 0047), so the CLI can print what moved before the report.
2188
2361
  */
2189
- locate: (pointer: string) => SourceLocation | undefined;
2362
+ onRelocated?: (result: RelocateResult) => void;
2190
2363
  }
2191
- /** The join an external-metadata config asks for: `path` unless it names a field. */
2192
- declare function externalMetadataJoin(manifest: Pick<ExternalMetadataConfig, "join">): string;
2193
- /**
2194
- * Load every manifest of every collection the run covers. Resolves to `null`
2195
- * when none of them declares one, which is every setup that existed before
2196
- * this feature.
2197
- *
2198
- * Every refusal is a `DocmetaError`: the manifest is a config-supplied input,
2199
- * and one that is missing or misshapen is the run's problem, not a
2200
- * document's (0014).
2201
- */
2202
- declare function loadExternalMetadata(collections: readonly CollectionConfig[], opts: LoadExternalMetadataOptions): Promise<ExternalMetadataIndex | null>;
2203
- /**
2204
- * Merge the external metadata for one document into its extracted metadata.
2205
- *
2206
- * `label` is the document as the run spells it, relative to `base`; a path
2207
- * entry matches on the resolved absolute path, never on the spelling, so a
2208
- * positional run from a subdirectory finds the same entry a config-corpus
2209
- * run does. A field entry matches on the document's own value of the join
2210
- * field, wherever the document lives. Stdin never matches a path entry:
2211
- * there is no file behind it.
2212
- *
2213
- * `memberOf` names the collections this document belongs to, and only their
2214
- * manifests are consulted (0041 rule 4). It is the caller's `memberOf(...)`
2215
- * result, computed once per file.
2216
- *
2217
- * `present`, `format` and the document's own positions are untouched. A
2218
- * manifest key is not in the document, so `lineFor` keeps answering
2219
- * `undefined` for it, and `locate` answers instead.
2220
- *
2221
- * A join field the page holds encrypted (proposal 0045) is decrypted with
2222
- * `options.encryptionKey` before it is matched. With no key, and a manifest
2223
- * of this document's collections joining on that field, the run cannot match
2224
- * and refuses. A ciphertext that does not decrypt matches nothing.
2225
- */
2226
- declare function mergeExternalMetadata(label: string, extracted: ExtractedMetadata, index: ExternalMetadataIndex | null, memberOf: readonly string[], base: string, options?: {
2227
- encryptionKey?: () => string | undefined;
2228
- }): MergedMetadata;
2229
- /** The `/key` pointer for an external-metadata finding, RFC 6901 escaped. */
2230
- declare function externalMetadataPointer(key: string): string;
2231
- /**
2232
- * Path entries naming no loaded document.
2233
- *
2234
- * `loaded` are the run's file labels, relative to `base`. Checked only when
2235
- * the run is the config corpus (the same invariant corpus checks use): a
2236
- * positional path means the operator chose to look at part of the corpus,
2237
- * and an entry for the rest is expected, not orphaned.
2238
- */
2239
- declare function orphanEntries(index: ExternalMetadataIndex | null, loaded: readonly string[], base: string, collections?: readonly string[]): ExternalMetadataEntry[];
2240
- /**
2241
- * Field entries no loaded document matched (0039). `matched` is field -> the
2242
- * values documents in the run carried, which the caller collects from each
2243
- * document's `joins` — so this runs after the per-file loop, under the same
2244
- * corpus invariant as `orphanEntries`.
2245
- */
2246
- declare function orphanJoins(index: ExternalMetadataIndex | null, matched: ReadonlyMap<string, ReadonlySet<string>>, collections?: readonly string[]): ExternalMetadataEntry[];
2247
- /** The operational error an orphan check raises, naming the first entry. */
2248
- declare function orphanError(orphans: readonly ExternalMetadataEntry[]): DocmetaError;
2249
2364
 
2250
- declare class Validator {
2251
- private readonly schemaOptions;
2365
+ declare function runFill(opts: FillOptions): Promise<FillRun>;
2366
+
2367
+ interface DeriveOptions {
2368
+ inputs: string[];
2252
2369
  /**
2253
- * How this validator's schemas are loaded: the disk cache location, its TTL,
2254
- * and `--offline`. Held per instance rather than read from module state, so
2255
- * two differently-configured validations in one process each get their own
2256
- * settings.
2257
- *
2258
- * That is not full isolation, and the difference matters to a library
2259
- * caller: `schema-registry` keeps a process-wide memo of fetched schemas, so
2260
- * one validator's successful fetch is visible to another. `offline` is
2261
- * excluded from that sharing on purpose — an offline validator will not be
2262
- * served something this process pulled over the network — but the memo is
2263
- * still shared, so a URL fetched once is not re-fetched per instance.
2370
+ * `--collection <name>`, repeatable: stamp only the named configured
2371
+ * collections instead of every declared one (proposal 0041). Cannot be
2372
+ * combined with paths.
2264
2373
  */
2265
- constructor(schemaOptions?: LoadSchemaOptions);
2266
- private ajvByDialect;
2374
+ collections?: string[];
2375
+ /** `--fields`: the managed fields to stamp this run; config `derive.fields` otherwise. */
2376
+ fields?: string[];
2377
+ /** `--sources`: the sources to consult; config `derive.sources`, else all four. */
2378
+ sources?: string[];
2379
+ /** `--dry-run`: report what would change and write nothing. */
2380
+ dryRun?: boolean;
2381
+ /** `--check`: implies `dryRun`; stale and unset fields are findings. */
2382
+ check?: boolean;
2383
+ /** Use the on-disk GitHub or GitLab review cache. Default true. */
2384
+ cache?: boolean;
2385
+ /** `--as` format override (extractor name). */
2386
+ as?: string;
2387
+ exts?: string[];
2388
+ exclude?: string[];
2389
+ configPath?: string;
2390
+ /** `--no-config`: skip config discovery and use the built-in defaults. */
2391
+ noConfig?: boolean;
2392
+ cwd?: string;
2393
+ /** Permit an input set that resolves to zero files (see `assertNonEmpty`). */
2394
+ allowEmpty?: boolean;
2267
2395
  /**
2268
- * Keyed on the in-flight *promise*, not the resolved validator. Caching the
2269
- * result made this a check-then-act race: `fill` walks files through a worker
2270
- * pool, so every worker missed the cache while the first `loadSchema` was
2271
- * still pending and they all then compiled the same schema into the one
2272
- * shared per-dialect Ajv. Ajv registers a schema's `$id` on the first compile
2273
- * and rejects the second with "schema with key or id ... already exists",
2274
- * which took down any multi-file run against an $id-bearing schema. Storing
2275
- * the promise before the first await lets the losers await the one compile.
2396
+ * `--no-gitignore` (false). Absent leaves config `respectGitignore:` in
2397
+ * charge, which itself defaults to on.
2276
2398
  */
2277
- private cache;
2278
- private ajvFor;
2399
+ respectGitignore?: boolean;
2400
+ /** Diagnostics for the user; the CLI writes these to stderr. */
2401
+ onNotice?: (message: string) => void;
2402
+ /** Called once when a config governs the run, so the CLI can report it. */
2403
+ onConfigLoaded?: (info: ConfigNotice) => void;
2404
+ /** The clock an uncommitted body change is dated by. Test seam; default `new Date()`. */
2405
+ now?: () => Date;
2406
+ /** The review client, for every repository in the run. Test seam; default `gh` / `glab`. */
2407
+ reviews?: ReviewClient;
2279
2408
  /**
2280
- * Synchronous by design: the `cache.set` has to happen in the same tick as
2281
- * the miss, or a second caller can slip in before the entry exists.
2409
+ * How to ask for a new encryption key when a field its schema marks
2410
+ * `x-manni-encrypt` is about to be stamped and no key is available
2411
+ * (proposal 0045). The CLI passes `terminalConfirm()`, which is `undefined`
2412
+ * off a terminal; absent, such a stamp refuses (exit 2). A dry run never
2413
+ * asks: it writes nothing.
2282
2414
  */
2283
- private compile;
2284
- private compileUncached;
2415
+ confirm?: Confirm;
2285
2416
  /**
2286
- * The instance pointers of `data` that carry `x-manni-encrypt: true` under
2287
- * any schema in `refs`, in the order the validator evaluated them.
2288
- *
2289
- * A first pass with the recording keyword, so a mark counts exactly where
2290
- * validation would evaluate it. Only present values are marked: Ajv applies
2291
- * a property's subschema to a property that exists. A branch Ajv does not
2292
- * take (`then` behind a failing `if`, an `anyOf` branch after a passing
2293
- * one) contributes nothing; a branch it takes contributes its marks
2294
- * whether or not the branch passes, because a ciphertext routinely fails
2295
- * the rest of its own subschema until it is decrypted.
2417
+ * The environment `MANNI_ENCRYPTION_KEY` is read from. Defaults to
2418
+ * `process.env`; tests pass their own.
2296
2419
  */
2297
- markedPointers(data: Record<string, unknown>, refs: string[]): Promise<Set<string>>;
2420
+ env?: NodeJS.ProcessEnv;
2298
2421
  /**
2299
- * Validate `data` against every schema in `refs`. Returns all violations,
2300
- * each tagged with the schema that produced it and a source line via
2301
- * `lineFor`.
2302
- *
2303
- * `colFor` is optional and additive: this signature is public, so a fourth
2304
- * *required* parameter — or a widened third one — would be a consumer break.
2305
- * Callers with an extractor that supplies no column pass nothing and get the
2306
- * previous behavior exactly.
2422
+ * `--generated-by <name>` (proposal 0046): the machine uncommitted body
2423
+ * lines go to, or the lines a `<path>:L1-L2` positional names. Absent reads
2424
+ * `MANNI_GENERATED_BY` from `env`; an empty value is unset either way.
2307
2425
  */
2308
- validate(data: Record<string, unknown>, refs: string[], lineFor: (pointer: string) => number | undefined, colFor?: (pointer: string) => number | undefined,
2426
+ generatedBy?: string;
2309
2427
  /**
2310
- * Where a merged value lives when it is not in the document (proposal
2311
- * 0037): a manifest's file and line. Consulted before `lineFor`,
2312
- * and additive in the way `colFor` was.
2428
+ * Called with relocate's result after the user accepts a P1 offer
2429
+ * (proposal 0047), so the CLI can print what moved before the report.
2313
2430
  */
2314
- locate?: (pointer: string) => SourceLocation | undefined): Promise<FieldError[]>;
2431
+ onRelocated?: (result: RelocateResult) => void;
2432
+ }
2433
+ interface DeriveFileResult {
2434
+ file: string;
2435
+ /** Extractor/format used; `unknown` when none matched the file. */
2436
+ format: string;
2437
+ /** One entry per requested field, in the requested order. Empty on `error`. */
2438
+ fields: DerivedField[];
2439
+ /**
2440
+ * Whether writing the stale and unset fields changed the document, or
2441
+ * would have but for `dryRun`. Computed from the writer's output, so a
2442
+ * patch the format serializes to the same bytes is not a change.
2443
+ */
2444
+ changed: boolean;
2445
+ /** Why the file could not be derived or written; the run goes on without it. */
2446
+ error?: string;
2447
+ /**
2448
+ * Under `check`, the findings for this file: one per stale or unset field,
2449
+ * at the field's line, plus one for an `error`. Absent otherwise.
2450
+ */
2451
+ findings?: FieldError[];
2452
+ }
2453
+ interface DeriveSummary {
2454
+ files: number;
2455
+ /** Files whose document changed, or would have under `dryRun`. */
2456
+ changed: number;
2457
+ /** Fields whose write reached the disk: always 0 under `dryRun` and `check`. */
2458
+ written: number;
2459
+ /**
2460
+ * `provenance` ranges whose write reached the disk (proposal 0046): always
2461
+ * 0 under `dryRun` and `check`. Present only when the run derives
2462
+ * `provenance`.
2463
+ */
2464
+ ranges?: number;
2465
+ stale: number;
2466
+ unset: number;
2467
+ unknown: number;
2468
+ errors: number;
2469
+ }
2470
+ interface DeriveRun {
2471
+ results: DeriveFileResult[];
2472
+ summary: DeriveSummary;
2473
+ dryRun: boolean;
2474
+ check: boolean;
2475
+ /** One status per source the run consulted; a source nobody asked for is absent. */
2476
+ sources: Partial<Record<DeriveSource, SourceStatus$1>>;
2477
+ /** Where the run stood, for the SARIF reporter under `check`. See `ValidateRun.frame`. */
2478
+ frame: FingerprintContext;
2479
+ }
2480
+ declare function runDerive(opts: DeriveOptions): Promise<DeriveRun>;
2481
+
2482
+ /**
2483
+ * `relocate` (proposal 0047): move every value to where its schema's
2484
+ * `x-manni-location` mark and the config's manifests say it belongs.
2485
+ *
2486
+ * Out of the page and into a manifest go the values a schema prefers in
2487
+ * external metadata and the values a manifest already owns. Out of a manifest
2488
+ * and into the page go the values a schema prefers on the page. The
2489
+ * collection, manifest file and config entry a value needs are created on the
2490
+ * way, and a change to a manifest's `keys:` covers every member page of its
2491
+ * collection. The planning and writing live in `core/relocation.ts`, which the
2492
+ * writers' and validate's offers share; this is the command around it.
2493
+ *
2494
+ * Two refusals come before the config is read, because each rules out the
2495
+ * whole run: stdin, which is not a document a manifest can name, and
2496
+ * `--no-config`, which leaves nowhere to declare a manifest.
2497
+ */
2498
+
2499
+ interface RelocateOptions {
2500
+ /** Files, directories and globs. Empty falls back to the configured collections. `-` is refused. */
2501
+ inputs: string[];
2502
+ /** `--fields`: only these keys. Each must carry a mark, or be manifest-owned, for some file. */
2503
+ fields?: string[];
2504
+ /** `--collection <name>`, repeatable: run over these configured collections. */
2505
+ collections?: string[];
2506
+ /** `-s/--schema`, repeatable: the schema set every page is judged by. */
2507
+ cliSchemas?: string[];
2508
+ /** `--dry-run`: report what would move and be created; write nothing. */
2509
+ dryRun?: boolean;
2510
+ /** `--as`: force an extractor. */
2511
+ as?: string;
2512
+ exts?: string[];
2513
+ exclude?: string[];
2514
+ configPath?: string;
2515
+ /** `--no-config`: refused, since relocate writes the config. */
2516
+ noConfig?: boolean;
2517
+ cwd?: string;
2518
+ allowEmpty?: boolean;
2519
+ /** `--no-gitignore` (false). Absent leaves config `respectGitignore:` in charge. */
2520
+ respectGitignore?: boolean;
2521
+ onNotice?: (message: string) => void;
2522
+ onConfigLoaded?: (info: ConfigNotice) => void;
2523
+ /** Where `MANNI_ENCRYPTION_KEY` is read, for an encrypted join field. Defaults to `process.env`. */
2524
+ env?: NodeJS.ProcessEnv;
2315
2525
  }
2526
+ declare function runRelocate(opts: RelocateOptions): Promise<RelocateResult>;
2316
2527
 
2317
2528
  /** One value re-encrypted: where, and the ciphertext before and after. */
2318
2529
  interface ReencryptedValue {
@@ -3271,7 +3482,7 @@ interface CitationSource {
3271
3482
  /** The git commit hash the pin was taken at: 7 to 64 lowercase hex. */
3272
3483
  "commit-sha"?: string;
3273
3484
  }
3274
- /** One entry of `citations`, as the schema (`manni:citations:1.0.0-proposal.3`) spells it. */
3485
+ /** One entry of `citations`, as the schema (`manni:citations:1.0.0-proposal.4`) spells it. */
3275
3486
  interface Citation {
3276
3487
  id?: string;
3277
3488
  claim?: CitationClaim;
@@ -4993,4 +5204,4 @@ declare namespace index {
4993
5204
  export { type index_EncryptionContext as EncryptionContext, index_KeyError as KeyError, type index_KeyRotateOptions as KeyRotateOptions, type index_KeyRotateResult as KeyRotateResult, type index_KeySetOptions as KeySetOptions, type index_KeySetResult as KeySetResult, type index_KeySource as KeySource, type index_ResolvedKey as ResolvedKey, type index_RotateManifest as RotateManifest, type index_RotateOutcome as RotateOutcome, type index_RotatePage as RotatePage, type index_RotatedCitation as RotatedCitation, type index_RotatedManifestValue as RotatedManifestValue, type index_RotatedMetadata as RotatedMetadata, type index_RotatedValue as RotatedValue, type index_SkippedCitation as SkippedCitation, type index_SkippedManifestValue as SkippedManifestValue, type index_SkippedMetadata as SkippedMetadata, type index_SkippedValue as SkippedValue, index_decryptValue as decryptValue, index_encryptValue as encryptValue, index_isEncryptedValue as isEncryptedValue, index_resolveEncryptionKey as resolveEncryptionKey, index_runKeyRotate as runKeyRotate, index_runKeySet as runKeySet };
4994
5205
  }
4995
5206
 
4996
- export { type ApplyOptions, type Approval, type BaselineSummary, BinMissing, type BuiltinDerivableField, COMMON_FORMATS, type CheckConfig, type CollectionConfig, type CommandSourceOptions, type CommandSourceResult, type CommonFormat, type ConfigNotice, DEFAULT_SCHEMAS, DEFAULT_TTL_HOURS, DEFAULT_VENDOR_DIR, DERIVABLE_FIELDS, DERIVED_KEYWORD, DERIVED_STALE_SCHEMA, DERIVE_FORMATS, DERIVE_SOURCES, type DerivableField, type DeriveCommand, type DeriveCommandConfig, type DeriveConfig, type DeriveContext, type DeriveFileResult, type DeriveInput, type DeriveOptions, type DeriveReportFormat, type DeriveReportOptions, type DeriveResult, type DeriveRun, type DeriveSource, type DeriveSummary, type DerivedField, type DerivedRecord, type DerivedStatus, type DerivedValue, type DocmetaConfig, DocmetaError, type DocumentRefTrust, EXTERNAL_DUPLICATE_SCHEMA, EXTERNAL_KEYWORD, EXTERNAL_METADATA_FETCH_MAX_BYTES, EXTERNAL_METADATA_FETCH_TIMEOUT_MS, EXTERNAL_OWNED_SCHEMA, type ExternalMetadataCollision, type ExternalMetadataConfig, type ExternalMetadataEntry, type ExternalMetadataFetchOptions, type ExternalMetadataIndex, type ExternalMetadataJoin, type ExternalMetadataValue, type ExtractOptions, type ExtractedMetadata, FIELD_SOURCES, FILL_FORMATS, type FetchedSchema, type FieldError, type FillConfig, type FillFileResult, type FillOptions, type FillReportFormat, type FillReportOptions, type FillRun, type FillSummary, type FilledField, type FingerprintContext, type FrontmatterFlavor, type FrontmatterLocation, type GetFileResult, type GetOptions, type GetReportOptions, GitHubClient, GitLabClient, INTEGRITY_SHAPE, type JunitOptions, type LoadExternalMetadataOptions, type LoadSchemaOptions, type LoadedConfig, type MergedChange, type MergedMetadata, type MetadataExtractor, type MetadataPatch, PATH_JOIN, PATH_PLACEHOLDER, QUERY_FORMATS, type QueryChange, type QueryFormat, type QueryOptions, type QueryReportOptions, type QueryRun, REPORT_FORMATS, RESOLVED_VIEW, REVIEW_CACHE_DIR, REVIEW_CACHE_VERSION, type ReadOptions, type ReencryptMetadataResult, type ReencryptedValue, type RemoteIdentity, type ReportFormat, type ReportOptions, ReviewCache, type ReviewClient, type ReviewFacts, type ReviewSourceInput, type ReviewSourceResult, type Run, type RunConfig, type RunConfigOptions, type RunSummary, SCHEMA_CACHE_DIR, SCHEMA_CACHE_VERSION, type SarifOptions, SchemaCache, type SchemaCacheConfig, type SchemaCacheEntry, type SchemaEntry, type SchemaPin, type SchemaRefEntry, type SchemaTrustConfig, type SkipReason, type SourceLocation, type SourceStatus$1 as SourceStatus, type SpawnOptions, type ValidateOptions, type ValidateRun, type ValidationResult, Validator, type VendorOptions, type VendorResult, applyFrontmatter, argvFor, assertSourcesAvailable, cachedClient, index$1 as cite, classifyRef, collectSchemaPins, compareDerived, consultedSources, createResolvedView, createReviewClient, deriveFromCommands, deriveFromReviews, deriveMetadata, externalMetadataJoin, externalMetadataPointer, externalMetadataUrlProblem, extractFrontmatter, extractorForExtension, fetchExternalMetadata, fetchSchemaBytes, frontmatterInnerText, getSchemasInfo, identityFromOrigin, integrityOf, isBuiltinField, isCommonFormat, isDeriveFormat, isDeriveSource, isErrorSeverity, isFillFormat, isIntegrity, isMember, isPerFile, isQueryFormat, isReportFormat, index as key, listBuiltins, loadConfig, loadExternalMetadata, loadSchema, locateFrontmatter, memberOf, mentionsResolved, mergeExternalMetadata, orphanEntries, orphanError, orphanJoins, parseCollections, parseConfig, parseOriginUrl, rebaseConfigSchemaRefs, reencryptMetadata, render, renderDerive, renderFill, renderFillGithub, renderGet, renderJunit, renderQuery, renderQueryCsv, renderSarif, resolveRunConfig, resolveSchemaSet, resolvedColumns, run, runDerive, runFill, runGet, runQuery, runValidate, runVendorSchema, schemaCacheDir, schemaEntryRef, schemaLoadOptions, selectCollections, sourcesFor, staleFindings, stringifyValue, supportedExtensions, valueOf, vendorFileName, writeFileAtomic };
5207
+ export { type ApplyOptions, type Approval, type BaselineSummary, BinMissing, type BuiltinDerivableField, COMMON_FORMATS, type CheckConfig, type CollectionConfig, type CommandSourceOptions, type CommandSourceResult, type CommonFormat, type ConfigNotice, DEFAULT_SCHEMAS, DEFAULT_TTL_HOURS, DEFAULT_VENDOR_DIR, DERIVABLE_FIELDS, DERIVED_KEYWORD, DERIVED_STALE_SCHEMA, DERIVE_FORMATS, DERIVE_SOURCES, type DerivableField, type DeriveCommand, type DeriveCommandConfig, type DeriveConfig, type DeriveContext, type DeriveFileResult, type DeriveInput, type DeriveOptions, type DeriveReportFormat, type DeriveReportOptions, type DeriveResult, type DeriveRun, type DeriveSource, type DeriveSummary, type DerivedField, type DerivedRecord, type DerivedStatus, type DerivedValue, type DocmetaConfig, DocmetaError, type DocumentRefTrust, EXTERNAL_DUPLICATE_SCHEMA, EXTERNAL_KEYWORD, EXTERNAL_METADATA_FETCH_MAX_BYTES, EXTERNAL_METADATA_FETCH_TIMEOUT_MS, EXTERNAL_OWNED_SCHEMA, type ExternalMetadataCollision, type ExternalMetadataConfig, type ExternalMetadataEntry, type ExternalMetadataFetchOptions, type ExternalMetadataIndex, type ExternalMetadataJoin, type ExternalMetadataValue, type ExtractOptions, type ExtractedMetadata, FIELD_SOURCES, FILL_FORMATS, type FetchedSchema, type FieldError, type FieldLocation, type FillConfig, type FillFileResult, type FillOptions, type FillReportFormat, type FillReportOptions, type FillRun, type FillSummary, type FilledField, type FingerprintContext, type FrontmatterFlavor, type FrontmatterLocation, type GetFileResult, type GetOptions, type GetReportOptions, GitHubClient, GitLabClient, INTEGRITY_SHAPE, type JunitOptions, LOCATION_KEYWORD, type LoadExternalMetadataOptions, type LoadSchemaOptions, type LoadedConfig, type LocationPreference, type MergedChange, type MergedMetadata, type MetadataExtractor, type MetadataPatch, PATH_JOIN, PATH_PLACEHOLDER, QUERY_FORMATS, type QueryChange, type QueryFormat, type QueryOptions, type QueryReportOptions, type QueryRun, REPORT_FORMATS, RESOLVED_VIEW, REVIEW_CACHE_DIR, REVIEW_CACHE_VERSION, type ReadOptions, type ReencryptMetadataResult, type ReencryptedValue, type RelocateOptions, type RelocateResult, type RemoteIdentity, type ReportFormat, type ReportOptions, ReviewCache, type ReviewClient, type ReviewFacts, type ReviewSourceInput, type ReviewSourceResult, type Run, type RunConfig, type RunConfigOptions, type RunSummary, SCHEMA_CACHE_DIR, SCHEMA_CACHE_VERSION, type SarifOptions, SchemaCache, type SchemaCacheConfig, type SchemaCacheEntry, type SchemaEntry, type SchemaPin, type SchemaRefEntry, type SchemaTrustConfig, type SkipReason, type SourceLocation, type SourceStatus$1 as SourceStatus, type SpawnOptions, type ValidateOptions, type ValidateRun, type ValidationResult, Validator, type VendorOptions, type VendorResult, applyFrontmatter, argvFor, assertSourcesAvailable, cachedClient, index$1 as cite, classifyRef, collectSchemaPins, compareDerived, consultedSources, createResolvedView, createReviewClient, deriveFromCommands, deriveFromReviews, deriveMetadata, externalMetadataJoin, externalMetadataPointer, externalMetadataUrlProblem, extractFrontmatter, extractorForExtension, fetchExternalMetadata, fetchSchemaBytes, frontmatterInnerText, getSchemasInfo, identityFromOrigin, integrityOf, isBuiltinField, isCommonFormat, isDeriveFormat, isDeriveSource, isErrorSeverity, isFillFormat, isIntegrity, isMember, isPerFile, isQueryFormat, isReportFormat, index as key, listBuiltins, loadConfig, loadExternalMetadata, loadSchema, locateFrontmatter, memberOf, mentionsResolved, mergeExternalMetadata, orphanEntries, orphanError, orphanJoins, parseCollections, parseConfig, parseOriginUrl, rebaseConfigSchemaRefs, reencryptMetadata, render, renderDerive, renderFill, renderFillGithub, renderGet, renderJunit, renderQuery, renderQueryCsv, renderSarif, resolveRunConfig, resolveSchemaSet, resolvedColumns, run, runDerive, runFill, runGet, runQuery, runRelocate, runValidate, runVendorSchema, schemaCacheDir, schemaEntryRef, schemaLoadOptions, selectCollections, sourcesFor, staleFindings, stringifyValue, supportedExtensions, valueOf, vendorFileName, writeFileAtomic };