diff --git a/AGENTS.md b/AGENTS.md index ab888b6..5c03741 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,10 @@ tests. The approved scope is the [Support Desk enhancement plan](https://github. authoring contexts, report queries and bounded resumable repair; retain the [public release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). All four `0.1.5` packages completed verified trusted publication for answering - read batching; retain the [current release receipt](docs/BOOTSTRAP.md#current-verified-015-release). + read batching; retain the [historical release receipt](docs/BOOTSTRAP.md#current-verified-015-release). + All four `0.1.6` packages completed verified trusted publication for MCP metadata + compatibility. Retain the [current release receipt](docs/BOOTSTRAP.md#current-verified-016-release). + The synchronized `0.1.7` source candidate remains unpublished. Grouped reads establish no universal query or CPU budget. Host dependency adoption and real-host acceptance remain separate. - Never implement a database, authorization role model, identity/session/token diff --git a/README.md b/README.md index cc0baaa..598238a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Hosts own their users, storage, authorization policy, interfaces, and deployment Knowledge Base owns collection policy, immutable article revisions, validation, and exact publication approval. It requires no GitHub connection or AI provider. -> Development status as of 2026-11-10: KB-01 through KB-03 provide contracts, pure domain +> Development status as of 2026-11-12: KB-01 through KB-03 provide contracts, pure domain > transitions, authorized application/persistence, and bounded retrieval/repair. > [Merged KB-04 source](https://github.com/pegma-dev/knowledge-base/pull/5) adds > the optional five-operation HTTP/MCP adapter and authenticated protocol proof. @@ -27,7 +27,10 @@ and exact publication approval. It requires no GitHub connection or AI provider. > All four `0.1.5` packages completed > [verified trusted publication](docs/BOOTSTRAP.md#current-verified-015-release) > for answering read batching, including strict registry/provenance and public-consumer -> verification. Host dependency adoption remains separate. +> verification. All four `0.1.6` packages completed +> [verified trusted publication](docs/BOOTSTRAP.md#current-verified-016-release) +> for MCP extension metadata compatibility. The `0.1.7` candidate remains unpublished. +> Host dependency adoption remains separate. > Actual two-host existing-login/client acceptance remains open. > Host activation remains separately gated; this repository supplies no hosted KB. @@ -168,9 +171,10 @@ publishers are configured through the CLI. Agent Access's verified trusted are complete; prior exact receipts remain historical evidence. At the `0.1.5` release checkpoint, all four KB packages had `latest: 0.1.5`; Agent Access remained at `latest: 0.1.1`; all retained `bootstrap: 0.1.0`. Dist-tags are mutable -observations. The [current receipt](docs/BOOTSTRAP.md#current-verified-015-release) +observations. The [retained `0.1.5` receipt](docs/BOOTSTRAP.md#current-verified-015-release) binds the original artifact, exact manifest, authenticated original writers and -strict verification. Read batching establishes no universal backend query or +strict verification. The [current `0.1.6` receipt](docs/BOOTSTRAP.md#current-verified-016-release) +records the later verified metadata compatibility release. Read batching establishes no universal backend query or CPU budget. Neither registry publication nor synthetic proof satisfies real host acceptance or approves activation. diff --git a/docs/AGENT_API.md b/docs/AGENT_API.md index 2b744b7..0339aab 100644 --- a/docs/AGENT_API.md +++ b/docs/AGENT_API.md @@ -11,7 +11,9 @@ The governed authoring-context pair and optional aggregate report query shipped in [`0.1.4`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). All four synchronized `0.1.5` packages have completed verified trusted publication for answering read batching; see the -[current receipt](BOOTSTRAP.md#current-verified-015-release). Changed source +[retained receipt](BOOTSTRAP.md#current-verified-015-release). The current verified +release is [`0.1.6`](BOOTSTRAP.md#current-verified-016-release). The `0.1.7` candidate +remains unpublished. Changed source requires its own review and current-head gates. Agent Access's verified public `0.1.1` producer prerequisite is closed; see the [release receipt](BOOTSTRAP.md#verified-agent-access-prerequisite). Passing @@ -279,7 +281,7 @@ are advertised, using the five names above with useful strict input JSON schemas. Client metadata and capability objects are bounded and validated before reaching the SDK; they grant no server authority. -The unpublished `0.1.6` source candidate accepts opaque JSON extension fields +The verified [`0.1.6` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6) accepts opaque JSON extension fields inside `params._meta` on initialize, ping, tools/list, tools/call, and the initialized/cancelled notifications. If present, `progressToken` retains its existing shape validation: a string of at most 128 characters or a safe integer, diff --git a/docs/AGENT_WORKFLOW.md b/docs/AGENT_WORKFLOW.md index 2905f5b..d1da881 100644 --- a/docs/AGENT_WORKFLOW.md +++ b/docs/AGENT_WORKFLOW.md @@ -1,5 +1,9 @@ # Agent authoring and test-evidence workflow +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + The [merged KB-04 source](https://github.com/pegma-dev/knowledge-base/pull/5) adds optional authoring transports over the existing Knowledge Base application. [KB-05 release-preparation source](https://github.com/pegma-dev/knowledge-base/pull/6) @@ -11,7 +15,7 @@ Governed context reads and an optional aggregate report query shipped in [`0.1.4`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). All four synchronized `0.1.5` packages have completed verified trusted publication for answering read batching; see the -[current receipt](BOOTSTRAP.md#current-verified-015-release). Changed source +[retained receipt](BOOTSTRAP.md#current-verified-015-release). Changed source requires its own review and current-head gates. This document describes the composition and retained acceptance contract, not a live service or a client-compatibility claim. The exact wire contract is in @@ -216,7 +220,7 @@ trusted `0.1.1` release closed the public producer prerequisite at [release ledger](BOOTSTRAP.md#verified-agent-access-prerequisite) records exact identities, the successful attempt-2 workflow, and strict verification stdout. KB `0.1.4` and the answering read-batching `0.1.5` release have since completed -verified trusted publication; see the [current KB receipt](BOOTSTRAP.md#current-verified-015-release). +verified trusted publication; see the [retained KB receipt](BOOTSTRAP.md#current-verified-015-release). Changed source still requires its own gates. Both verified trusted dependencies precede production host assembly. Branches, copied source, local paths, and unpublished production tarballs cannot substitute for them. diff --git a/docs/BOOTSTRAP.md b/docs/BOOTSTRAP.md index 63da6ea..88c883a 100644 --- a/docs/BOOTSTRAP.md +++ b/docs/BOOTSTRAP.md @@ -7,13 +7,15 @@ The maintainer owns npm publication and external configuration. All four KB postflight passed at **2026-11-07T21:56:24Z**. Agent Access `0.1.0` also completed manual bootstrap and postflight. Neither bootstrap has OIDC provenance. KB's current verified trusted release is -[`0.1.5`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5); Agent Access +[`0.1.6`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6); Agent Access remains verified at `0.1.1`. Their receipts close public producer release -prerequisites only. The dated trusted KB `0.1.1`, `0.1.2`, `0.1.3` and `0.1.4` +prerequisites only. The dated trusted KB `0.1.1`, `0.1.2`, `0.1.3`, `0.1.4` and `0.1.5` receipts remain below as history. The answering read-batching `0.1.5` release completed its own review, current-head gates, trusted publication and strict -registry/consumer qualification. Host dependency adoption and acceptance remain -separate. +registry/consumer qualification. The [current `0.1.6` receipt](#current-verified-016-release) +records the later MCP metadata compatibility release. The `0.1.7` source candidate +remains unpublished and requires its own current-head gates and release. +Host dependency adoption and acceptance remain separate. The five KB/Agent Access trusted-publisher entries have been configured through the CLI. An actual trusted release still requires the reviewed source and @@ -86,7 +88,33 @@ the approved dependency set or establishes real-host acceptance. ## Verified Knowledge Base release -### Current verified `0.1.5` release +### Current verified `0.1.6` release + +All four synchronized KB `0.1.6` packages completed exact-registry-byte, native +signature, authenticated source-provenance and clean-consumer verification at +**2026-11-12T00:14:56.815468Z**. The +[`v0.1.6` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6) +and its [verification receipt](https://github.com/pegma-dev/knowledge-base/releases/download/v0.1.6/registry-verification.json) +bind signed source +[`b2946e149078e0ef460f970c2271c196ea9fc759`](https://github.com/pegma-dev/knowledge-base/commit/b2946e149078e0ef460f970c2271c196ea9fc759) +and annotated tag object `44a54d90973bc18356233bc31694163c5a80b5f9`. + +The original preparation artifact is `13900971990` from attempt `1`. Its +[prepared archive](https://github.com/pegma-dev/knowledge-base/releases/download/v0.1.6/knowledge-base-v0.1.6-original-artifact-13900971990.zip) +has SHA-256 `efd2327a1f1f3b4889b691c6562764389608d1d8d13350fa67da5a4fb4658960`. +The [exact manifest](https://github.com/pegma-dev/knowledge-base/releases/download/v0.1.6/manifest.json) +has SHA-256 `e92903283bb7fc851623846974301d33ca87ca8fbd5c1b4dd5e55ead4d908c86`. +Original package writers were attempts 1 through 4. The +[successful attempt 5](https://github.com/pegma-dev/knowledge-base/actions/runs/43120006429/attempts/5) +uploaded zero versions and verified four identical existing packages. Its +[separate unprivileged verification job](https://github.com/pegma-dev/knowledge-base/actions/runs/43120006429/job/130875137023) +completed the full registry and consumer checks. The linked public receipt +retains the original writer identities and provenance bindings. Host acceptance +remains separately gated. + + + +### Historical verified `0.1.5` release All four KB `0.1.5` packages completed exact-registry-byte, cryptographic signature/Sigstore, authenticated source-provenance and public-consumer @@ -279,7 +307,7 @@ admission or establish a durable host or actual client/staging acceptance. This release provides optional human-reviewed evidence reports. The later verified `0.1.4` release adds governed authoring contexts and optional report queries. The separately verified `0.1.5` release adds answering read batching. -Its current receipt above retains its own source and artifact identity. +Its retained receipt above retains its own source and artifact identity. Producer releases do not close Workers Free call/CPU acceptance, host activation or pilot gates. @@ -401,7 +429,7 @@ This closes the verified public Agent Access `0.1.1` prerequisite. The KB protocol proof now composes that exact registry producer with four packed KB candidate artifacts in a fresh consumer. KB `0.1.3` has its separate verified receipt above; the later `0.1.4` and `0.1.5` releases are also verified. The -current `0.1.5` receipt retains its own gates, source and artifact identity. +retained `0.1.5` receipt retains its own gates, source and artifact identity. Existing-login, current-Admin consent, every requested client/mode, and both real hosts remain separately unproven. @@ -480,11 +508,11 @@ must name this repository's exact `publish.yml` workflow and environment and explicitly permit direct publishing. Time new configurations to the prepared trusted release so their first-use expiry does not strand the release. -The synchronized current KB release is `0.1.5` with exact internal dependency +The synchronized current KB release is `0.1.6` with exact internal dependency pins. Any changed source needs its own review and current-head gates before a new release. The historical first advertised trusted release is `0.1.1`; its -receipt and those for `0.1.2`, `0.1.3` and `0.1.4` remain above alongside the -current verified `0.1.5` receipt. +receipt and those for `0.1.2` through `0.1.5` remain above alongside the +current verified `0.1.6` receipt. A previously manually published version cannot be republished through OIDC to add provenance. Run the full review/Node 22/24 gate for the newly reviewed commit, create its approved signed annotated version tag @@ -500,6 +528,6 @@ results with the release identity and independent manifest digest. The active KB protocol proof uses the verified registry producer `@pegma/agent-access@0.1.1`; historical source-producer evidence remains in [source preparation](SOURCE_PREPARATION.md). The verified KB `0.1.3` receipt -remains historical; KB `0.1.5` and Agent Access `0.1.1` public producer release +remains historical; KB `0.1.6` and Agent Access `0.1.1` public producer release prerequisites are closed. Both hosts still require their retained actual login/Admin-consent/client/staging acceptance. diff --git a/docs/COLLECTIONS.md b/docs/COLLECTIONS.md index 5141ae7..a4bd011 100644 --- a/docs/COLLECTIONS.md +++ b/docs/COLLECTIONS.md @@ -1,5 +1,9 @@ # Declared collections and durable layout +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + ## Design status The authoritative layout was written before KB-02 durable operations. The @@ -15,7 +19,7 @@ source is [merged](https://github.com/pegma-dev/knowledge-base/pull/5). The [verified `0.1.3` release](BOOTSTRAP.md#current-verified-013-release) is complete, as is the later [`0.1.4` trusted release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). The synchronized `0.1.5` answering read-batching release has completed verified -trusted publication; see its [current receipt](BOOTSTRAP.md#current-verified-015-release). +trusted publication; see its [retained receipt](BOOTSTRAP.md#current-verified-015-release). Changed-source gates, real-host acceptance, and production readiness remain separate. The earlier `0.1.1` release has a separate [historical receipt](BOOTSTRAP.md#historical-verified-011-release), as does diff --git a/docs/EVIDENCE_REPORTS.md b/docs/EVIDENCE_REPORTS.md index 971e66b..485d6be 100644 --- a/docs/EVIDENCE_REPORTS.md +++ b/docs/EVIDENCE_REPORTS.md @@ -1,11 +1,15 @@ # Human-reviewed evidence reports +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + `createKnowledgeEvidenceReports` shipped in the four synchronized, verified [`0.1.3` packages](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.3). The optional governed context pair and body-free `query` described below shipped in the qualified [`0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). Synchronized `0.1.5` has completed verified trusted publication for answering -read batching; see the [current release receipt](BOOTSTRAP.md#current-verified-015-release). +read batching; see the [retained release receipt](BOOTSTRAP.md#current-verified-015-release). Changed source still requires its own review and current-head gates. Source tests and local adapter fixtures do not establish host activation, actual client acceptance, or a real staging test. @@ -171,7 +175,10 @@ exactly the confirmation permission, `draftRead`, `evidenceRead` and either/or requirement supplies the public `getValidationRequirements` read prerequisite. Choose `evidenceSubmit` to review without draft-editing authority. The full view includes the report/submission, hashes, exact current draft/requirements, -`reviewBindingHash`, `expectedReportGeneration`, and any confirmation. Keep +`reviewBindingHash`, `expectedReportGeneration`, and any confirmation. Its `receipt` +is the canonical acknowledgement receipt for that same report snapshot, including +pending and rejected reports; reassessment rotates its cycle and reset fences its +epoch. The field does not change verifier or owner-only status authority. Keep these private; the agent's body-free `status` is not a staff listing or report download. Render untrusted report text safely and do not fetch submitted links. diff --git a/docs/HOST_COMPOSITION.md b/docs/HOST_COMPOSITION.md index 04f3c43..b5450e5 100644 --- a/docs/HOST_COMPOSITION.md +++ b/docs/HOST_COMPOSITION.md @@ -1,5 +1,9 @@ # Application and retrieval host composition +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + ## Status and ownership This documents the KB-02/KB-03 application and KB-04 transport host boundaries. @@ -19,7 +23,7 @@ human-reviewed report packages subsequently completed The governed authoring-context/report-query features shipped in the qualified [`0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). All four answering read-batching `0.1.5` packages have completed -[qualified trusted publication](BOOTSTRAP.md#current-verified-015-release), including +[retained qualified trusted publication](BOOTSTRAP.md#current-verified-015-release), including strict registry/provenance and public-consumer verification. Internal read-wave changes preserve the public ports and do not establish a universal Workers Free call/CPU allowance or live-host acceptance. Publication does not update either diff --git a/docs/RELEASING.md b/docs/RELEASING.md index 65ba100..11bca9f 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -41,13 +41,13 @@ authoring-context reads, report queries and bounded resumable repair. The [historical local receipt](BOOTSTRAP.md#current-verified-014-release) retains that release's separate publication boundary under its preserved anchor. -The current verified release is +The historical verified release is [`0.1.5`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5), the synchronized answering read-batching patch at signed source `6dae20df8dace50ad961d9c5fe8d28c90bf4918f`. All four registry packages completed exact-byte, signature/source-provenance and public-consumer qualification. The [final attempt-5 verification job](https://github.com/pegma-dev/knowledge-base/actions/runs/42821672972/job/129895026059) -and [current receipt](BOOTSTRAP.md#current-verified-015-release) bind the unchanged +and [retained receipt](BOOTSTRAP.md#current-verified-015-release) bind the unchanged original artifact and manifest. Original writer attempts 1 through 4 remain failed records; the final publisher uploaded zero packages and skipped four identical versions. The earlier gates/preparation were carried, not rerun in @@ -66,7 +66,7 @@ Changed source still needs all current-head gates before release preparation. No source merge configures publishers, creates a tag/release, or publishes npm packages. The [maintainer bootstrap ledger](BOOTSTRAP.md) retains the actual manual commands/stdout, exact identities, preparation runs/artifacts, and -independently retained digests. The qualified release versions are KB `0.1.5` +independently retained digests. The qualified release versions are KB `0.1.6` and Agent Access `0.1.1`. The manual `0.1.0` bootstraps and their dated dist-tag observations remain historical integrity receipts without OIDC provenance. @@ -85,22 +85,42 @@ their own current-head gates; historical results do not validate changed composition. Production hosts require verified trusted versions of both components and their separately retained acceptance. -## Unpublished 0.1.6 candidate - -All four source packages are synchronized at `0.1.6` for the MCP extension -metadata compatibility patch. The adapter accepts bounded opaque `params._meta` -values used by native clients. An optional `progressToken` must be a string of -at most 128 characters or a safe integer, without a registered-value allowlist. -Strict tool arguments, current authorization and existing complete-message -limits remain unchanged. It adds no tool, scope, durable record, credential or -migration. The generic SDK error-response mapping is unchanged. - -The current qualified release remains `0.1.5`; this candidate needs its own -current-head gates, review, signed-tag preparation, trusted publication and -strict complete-set registry verification. Existing `0.1.5` receipts and -tarballs remain unchanged. Hosts and Support Desk consumers must deliberately -align their exact Knowledge Base graph before adoption; producer qualification -does not close native-client or real-host acceptance. +## Verified 0.1.6 release + +All four [`0.1.6` packages](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6) +completed verified trusted publication for MCP extension metadata compatibility. +The adapter accepts bounded opaque `params._meta` values used by native clients. +An optional `progressToken` must be a string of at most 128 characters or a safe +integer, without a registered-value allowlist. Strict tool arguments, current +authorization and existing complete-message limits remain unchanged. The +release adds no tool, scope, durable record, credential or migration. The generic +SDK error-response mapping is unchanged. + +The [verified release receipt](BOOTSTRAP.md#current-verified-016-release) binds +the signed source, original prepared artifact and complete-set registry, +signature, source-provenance and clean-consumer verification. + +Existing release receipts, tag links and tarballs retain their original +identities. Host and native-client acceptance remain separately gated. + +## Unpublished 0.1.7 candidate + +All four source package versions and exact internal pins are synchronized at +`0.1.7`. The candidate adds the required `receipt: string` to the existing staff +`KnowledgeReportView` for its authenticated canonical report receipt. The read +refuses observed concurrent report or ledger changes before returning the view. +A host can associate the receipt with Support test results after refreshing the +governed KB context and checking exact accepted evidence and revocation DTOs +through authorized public reads. Actual receipt verification and owner-only +status remain bound to the original submitter. These host association checks +leave existing KB evidence acceptance unchanged. The candidate adds no tool, +scope, role or durable state. + +The current qualified release remains `0.1.6`. Combined candidate source requires +current-head Node 22 and 24 gates, review, signed-tag preparation, trusted +publication and strict complete-set registry verification before adoption. +Host and native-client acceptance remain separately gated. Read the +[application upgrade note](../packages/application/README.md#unpublished-017-candidate) for the receipt boundary and synchronized graph. ## Repository and development artifact gates diff --git a/docs/RETRIEVAL.md b/docs/RETRIEVAL.md index 8779cb1..acbf499 100644 --- a/docs/RETRIEVAL.md +++ b/docs/RETRIEVAL.md @@ -1,5 +1,9 @@ # KB-03 bounded retrieval +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + ## Design status This design was recorded before durable retrieval operations and synchronized @@ -15,7 +19,7 @@ qualified [`0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases includes governed authoring contexts, optional report queries and the bounded repair mode described below. Synchronized `0.1.5` has completed verified trusted publication for answering read batching; see its -[current receipt](BOOTSTRAP.md#current-verified-015-release). Source tests and +[retained receipt](BOOTSTRAP.md#current-verified-015-release). Source tests and repository gates, not this document, determine changed-source completion. KB-04's optional HTTP/MCP adapter source is [merged](https://github.com/pegma-dev/knowledge-base/pull/5). Real-host acceptance diff --git a/docs/SOURCE_PREPARATION.md b/docs/SOURCE_PREPARATION.md index 6314e2b..c91ecd6 100644 --- a/docs/SOURCE_PREPARATION.md +++ b/docs/SOURCE_PREPARATION.md @@ -1,5 +1,9 @@ # KB-05 source preparation +The current verified Knowledge Base release is +[`0.1.6`](BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + ## Scope and readiness KB-05 source preparation has two separately reviewed source slices. The earlier @@ -58,7 +62,7 @@ The optional human-report `0.1.3` release is now features subsequently shipped in the qualified [`0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4). Synchronized `0.1.5` has completed verified trusted publication for answering -read batching; see its [current receipt](BOOTSTRAP.md#current-verified-015-release). +read batching; see its [retained receipt](BOOTSTRAP.md#current-verified-015-release). Changed source still requires its own review and current-head gates. | Evidence area | This source slice | Separate remaining proof | @@ -268,9 +272,9 @@ A local candidate run on **2026-11-07** passed with `packedPackages: 4`, and five-operation positive/negative checks passed. It retained `liveHostsProven: false` and `targetClientAppsProven: 0`. A separate negative probe rejected a source override at stage 1 before external commands. -That dated proof does not validate later source changes. The current `0.1.5` +That dated proof does not validate later source changes. The historical `0.1.5` release has since completed its own gates, review, trusted publication and -strict verification; see the [release receipt](BOOTSTRAP.md#current-verified-015-release). +strict verification; see the [retained release receipt](BOOTSTRAP.md#current-verified-015-release). Future changed source requires fresh current-head Node 22/24 CI and review; each later release requires its own verified publication. @@ -310,7 +314,7 @@ The KB `0.1.3` trusted release completed complete-set registry integrity/signature/provenance verification and released-consumer proof; its [receipt](BOOTSTRAP.md#current-verified-013-release) is separate from these historical source records. The later `0.1.4` and answering read-batching `0.1.5` -releases are also qualified; see the [current receipt](BOOTSTRAP.md#current-verified-015-release). +releases are also qualified; see the [retained receipt](BOOTSTRAP.md#current-verified-015-release). Changed source retains its own review and current-head gates. Manual bootstrap is not OIDC provenance. Agent Access has its own publication history: diff --git a/examples/agent/README.md b/examples/agent/README.md index e106dc3..b98d018 100644 --- a/examples/agent/README.md +++ b/examples/agent/README.md @@ -1,5 +1,9 @@ # Packed local agent protocol proof +The current verified Knowledge Base release is +[`0.1.6`](../../docs/BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + Run `pnpm run agent:proof` from the repository after `pnpm install --frozen-lockfile`, on Node 22.6+ or Node 24. npm must be available. The proof needs public npm registry access and binds an @@ -21,7 +25,7 @@ real browser login, real staging execution, verified KB publication, or host act Real host/client acceptance and activation remain open. All four answering read-batching `0.1.5` packages have completed verified trusted -publication; see the [current receipt](../../docs/BOOTSTRAP.md#current-verified-015-release). +publication; see the [retained receipt](../../docs/BOOTSTRAP.md#current-verified-015-release). This proof packs the current working tree for source qualification and does not re-verify the immutable published `0.1.5` artifacts. The separate [qualified `0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4) diff --git a/examples/composition/README.md b/examples/composition/README.md index 8767f0a..61da573 100644 --- a/examples/composition/README.md +++ b/examples/composition/README.md @@ -1,5 +1,9 @@ # Fictional Knowledge Base composition +The current verified Knowledge Base release is +[`0.1.6`](../../docs/BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + This runnable Node example uses public package entry points and Storage Core's real memory Store. It demonstrates authoring, bound synthetic verification evidence, separate staff review/publication, bounded index repair, and bot-source @@ -30,7 +34,7 @@ The four-package `0.1.3` release has a All four packages subsequently completed qualified trusted publication at [`0.1.4`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4) for the governed context/query features. The answering read-batching `0.1.5` release is -also verified; see its [current receipt](../../docs/BOOTSTRAP.md#current-verified-015-release). +also verified; see its [retained receipt](../../docs/BOOTSTRAP.md#current-verified-015-release). Changed source requires its own review and current-head gates, followed by a separate verified release before host adoption. Production hosts retain their separate acceptance gates. diff --git a/package.json b/package.json index 1114abc..a9a87ec 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,11 @@ "@cloudflare/workers-types": "5.20260730.1", "@modelcontextprotocol/sdk": "1.32.2", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-application": "0.1.6", + "@pegma/knowledge-base-application": "0.1.7", "@pegma/knowledge-base-application-previous": "npm:@pegma/knowledge-base-application@0.1.1", - "@pegma/knowledge-base-contracts": "0.1.6", - "@pegma/knowledge-base-core": "0.1.6", - "@pegma/knowledge-base-mcp": "0.1.6", + "@pegma/knowledge-base-contracts": "0.1.7", + "@pegma/knowledge-base-core": "0.1.7", + "@pegma/knowledge-base-mcp": "0.1.7", "@pegma/spine": "0.1.2", "@pegma/storage-azure-tables": "0.4.0", "@pegma/storage-cloudflare-d1": "0.4.6", diff --git a/packages/application/README.md b/packages/application/README.md index d547435..90f9eae 100644 --- a/packages/application/README.md +++ b/packages/application/README.md @@ -23,6 +23,8 @@ in the verified The synchronized answering read-batching `0.1.5` release has completed verified trusted publication; see its [release receipt](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5). +The current verified synchronized release is +[`0.1.6`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6). Changed source still requires its own review and current-head gates. Backend query and CPU budgets require actual host measurements. These source README corrections apply to a future release. Published `0.1.5` tarballs, including @@ -195,6 +197,32 @@ no populated-namespace detection, layout switch or migration is automatic. The factory adds no agent scope, MCP tool, role, login, scheduler or provenance bridge. Hosts retain exact-publication and activation prerequisites. +### Unpublished 0.1.7 candidate + +The candidate adds required `readonly receipt: string` to the existing staff +`KnowledgeReportView` for pending, confirmed and rejected reads. It returns the +authenticated canonical receipt from the same current report snapshot as its +generation, hash and confirmation. Confirmation preserves the receipt, +reassessment rotates its cycle and ledger reset fences its epoch. + +The read refuses observed concurrent report or ledger changes before returning +the view. A host can associate the receipt with Support test results after +refreshing the governed KB context and checking the exact accepted evidence and +revocation DTOs through authorized `getEvidence` or an evidence-bearing +`getAuthoringContext` read. This supports a different authorized staff member +without changing existing KB evidence acceptance. Actual receipt verification +and owner-only status remain bound to the original submitter. Staff and resource +read guards, the five agent operations, scopes, roles and durable report state +remain unchanged. + +The verified [`0.1.6` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6) +remains the released graph. Combined `0.1.7` source requires its current-head +Node 22 and 24 gates, review and complete release verification before adoption. +Then align all four exact package versions together. Existing external pins and +the previous application writer at `0.1.1` remain unchanged. The extension +requires no data migration. Host acceptance and activation remain separately +gated, and existing release receipts and artifact bytes retain their identities. + ## Bounded retrieval and repair `listPortalCollections` and `searchPublishedArticles` require current portal diff --git a/packages/application/package.json b/packages/application/package.json index aa97c33..0c2bb56 100644 --- a/packages/application/package.json +++ b/packages/application/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-application", - "version": "0.1.6", + "version": "0.1.7", "description": "Authorized knowledge authoring, evidence, review, and publication over Pegma storage.", "license": "MIT", "type": "module", @@ -31,8 +31,8 @@ "dependencies": { "@pegma/audit": "0.2.0", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-contracts": "0.1.6", - "@pegma/knowledge-base-core": "0.1.6", + "@pegma/knowledge-base-contracts": "0.1.7", + "@pegma/knowledge-base-core": "0.1.7", "@pegma/spine": "0.1.2", "@pegma/storage-core": "0.4.0" }, diff --git a/packages/application/src/evidence-reports-types.ts b/packages/application/src/evidence-reports-types.ts index 5fcd41c..2b5c2f7 100644 --- a/packages/application/src/evidence-reports-types.ts +++ b/packages/application/src/evidence-reports-types.ts @@ -66,6 +66,7 @@ export interface KnowledgeEvidenceContext { } export interface KnowledgeReportView extends KnowledgeReportSummary { + readonly receipt: string; readonly evidence: EvidenceSubmission; readonly report: KnowledgeTestReport; readonly reportHash: string; diff --git a/packages/application/src/evidence-reports.ts b/packages/application/src/evidence-reports.ts index 9880494..e50889a 100644 --- a/packages/application/src/evidence-reports.ts +++ b/packages/application/src/evidence-reports.ts @@ -1352,6 +1352,16 @@ export function createKnowledgeEvidenceReports( // Re-resolve only after the awaited resource observations, preserving the // original credential's restricted permissions through final disclosure. await current(access, knowledgePermissions.evidenceSubmit); + // Close the epoch after every resource and current-authority await. + // These separate observations provide no cross-row lock. + const closingHead = await headVersion(articleId); + if ( + closingHead.value.ledgerEpoch !== latestHead.value.ledgerEpoch || + closingHead.value.status !== latestHead.value.status + ) + throw new KnowledgeEvidenceReportsError("ledger_epoch_changed"); + if (closingHead.version !== latestHead.version) + throw new KnowledgeEvidenceReportsError("ledger_changed"); return { target: { articleId, @@ -1360,7 +1370,7 @@ export function createKnowledgeEvidenceReports( kind: first.draft.revision.kind, }, requirements: first.requirements, - ledger: state(articleId, latestHead.value), + ledger: state(articleId, closingHead.value), ...(latestReport === undefined ? {} : { @@ -1465,14 +1475,17 @@ export function createKnowledgeEvidenceReports( ]); const articleId = scalar(input.articleId); const epoch = positive(input.ledgerEpoch); - await active(articleId, epoch); + const head = await headVersion(articleId); + if (head.value.ledgerEpoch !== epoch) + throw new KnowledgeEvidenceReportsError("ledger_epoch_changed"); + if (head.value.status !== "active") + throw new KnowledgeEvidenceReportsError("ledger_resetting"); const report = await load(articleId, epoch, scalar(input.reportId)); if (report.submittedBy !== access.principalId) throw new KnowledgeEvidenceReportsError("report_not_found"); await current(access, knowledgePermissions.evidenceSubmit); - await active(articleId, epoch); - // Finite final observation after authority/head awaits. A concurrent - // human decision rotates this generation/cycle; do not return old status. + // Compare the report before closing the epoch as the final await. + // A concurrent human decision must not return an old generation/cycle. const latest = await load(articleId, epoch, report.reportId); if ( latest.reportGeneration !== report.reportGeneration || @@ -1481,6 +1494,13 @@ export function createKnowledgeEvidenceReports( latest.reportHash !== report.reportHash ) throw new KnowledgeEvidenceReportsError("report_changed"); + const closingHead = await headVersion(articleId); + if (closingHead.value.ledgerEpoch !== epoch) + throw new KnowledgeEvidenceReportsError("ledger_epoch_changed"); + if (closingHead.value.status !== "active") + throw new KnowledgeEvidenceReportsError("ledger_resetting"); + if (closingHead.version !== head.version) + throw new KnowledgeEvidenceReportsError("report_changed"); return { ...acknowledgement(latest), status: latest.status }; }, async list(access, value) { @@ -1536,16 +1556,39 @@ export function createKnowledgeEvidenceReports( const articleId = scalar(input.articleId); const epoch = positive(input.ledgerEpoch); await active(articleId, epoch); - const report = await load(articleId, epoch, scalar(input.reportId)); + const observed = await observedReport( + articleId, + epoch, + scalar(input.reportId), + ); + const report = observed.value; const valueContext = await context(access, articleId, true); const reviewBindingHash = await knowledgeDigest({ report, context: valueContext, }); await staff(access); - await active(articleId, epoch); + const head = await headVersion(articleId); + if (head.value.ledgerEpoch !== epoch) + throw new KnowledgeEvidenceReportsError("ledger_epoch_changed"); + if (head.value.status !== "active") + throw new KnowledgeEvidenceReportsError("ledger_resetting"); + // Observe the report before the final epoch/head read. These separate + // observations provide no lock; return without another await. + const latest = await observedReport(articleId, epoch, report.reportId); + if (latest.version !== observed.version) + throw new KnowledgeEvidenceReportsError("report_changed"); + const latestHead = await headVersion(articleId); + if ( + latestHead.value.ledgerEpoch !== head.value.ledgerEpoch || + latestHead.value.status !== head.value.status + ) + throw new KnowledgeEvidenceReportsError("ledger_epoch_changed"); + if (latestHead.version !== head.version) + throw new KnowledgeEvidenceReportsError("ledger_changed"); return { ...summary(report), + receipt: acknowledgement(report).receipt, evidence: report.evidence, report: report.report, draft: valueContext.draft, diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 2e51472..43c5d2e 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -7,8 +7,10 @@ using host-resolved Authorization Core contexts. Identity and time types come from `@pegma/spine`. The current verified synchronized release is -[`0.1.5`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5), including -the application answering read-batching patch. Changed source still requires +[`0.1.6`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6), including +MCP extension metadata compatibility. The historical +[`0.1.5` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5) +provided application answering read batching. Changed source still requires its own review and current-head gates; host acceptance remains separate. These source README corrections apply to a future release. Published `0.1.5` tarballs, including their bundled README bytes, remain unchanged. diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 7193108..6658092 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-contracts", - "version": "0.1.6", + "version": "0.1.7", "description": "Provider-neutral knowledge collections, revisions, validation, and approval contracts.", "license": "MIT", "type": "module", diff --git a/packages/core/README.md b/packages/core/README.md index 082e24d..aaa0af2 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -5,8 +5,10 @@ transitions. It requires no Support Desk, GitHub, model, framework, database, or provider SDK. The current verified synchronized release is -[`0.1.5`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5), including -the application answering read-batching patch. Changed source still requires +[`0.1.6`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6), including +MCP extension metadata compatibility. The historical +[`0.1.5` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5) +provided application answering read batching. Changed source still requires its own review and current-head gates; host acceptance remains separate. These source README corrections apply to a future release. Published `0.1.5` tarballs, including their bundled README bytes, remain unchanged. diff --git a/packages/core/package.json b/packages/core/package.json index bcd7e6b..2fd797a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-core", - "version": "0.1.6", + "version": "0.1.7", "description": "Pure knowledge article, validation, and publication transitions.", "license": "MIT", "type": "module", @@ -29,7 +29,7 @@ "directory": "packages/core" }, "dependencies": { - "@pegma/knowledge-base-contracts": "0.1.6" + "@pegma/knowledge-base-contracts": "0.1.7" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/mcp/README.md b/packages/mcp/README.md index 8f0165d..746be45 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -5,15 +5,16 @@ adapts the authorized application API to bounded agent commands and the Model Context Protocol. Hosts compose it with their protected Knowledge Base endpoints; the package does not supply a hosted service. -All four Knowledge Base packages are verified published at -[`0.1.5`](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5), including -answering read batching and the aggregate report query introduced in `0.1.4`. +The historical synchronized +[`0.1.5` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.5) +includes answering read batching and the aggregate report query introduced in +`0.1.4`. The current verified synchronized release is `0.1.6`, described below. Changed source requires its own review and current-head gates. Host and actual client acceptance remain separate. These source README corrections apply to a future release. Published `0.1.5` tarballs, including their bundled README bytes, remain unchanged. -The synchronized `0.1.6` source candidate is unpublished. It accepts bounded +The verified [`0.1.6` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.6) accepts bounded opaque MCP `params._meta` extensions, including native-client correlation and standard trace fields, while retaining the existing `progressToken` shape validation: a string of at most 128 characters or a safe integer. Metadata @@ -23,6 +24,11 @@ ceilings, strict tool arguments and fresh host authentication remain unchanged. The official-SDK regression and packed protocol proof exercise fictional extension values; actual requested-client and host acceptance remain separate. +The unpublished `0.1.7` candidate synchronizes all four packages for the staff +report receipt extension. Its combined source requires current-head gates and +release verification before adoption. See the +[application upgrade note](https://github.com/pegma-dev/knowledge-base/blob/61dcaaf19f7a0db644709aef8f52a826f3c1b34d/packages/application/README.md#unpublished-017-candidate). + The contracts, core, and application packages remain independent of MCP, HTTP, provider SDKs, and login flows. Hosts choose this adapter when exposing agent access. The adapter pins `@modelcontextprotocol/sdk` at `1.32.2` and `zod` at diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 969f6d9..d4d3c26 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-mcp", - "version": "0.1.6", + "version": "0.1.7", "description": "Optional MCP transport for authorized Pegma knowledge authoring and validation.", "license": "MIT", "type": "module", @@ -32,9 +32,9 @@ "@cfworker/json-schema": "4.1.6", "@modelcontextprotocol/sdk": "1.32.2", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-application": "0.1.6", - "@pegma/knowledge-base-contracts": "0.1.6", - "@pegma/knowledge-base-core": "0.1.6", + "@pegma/knowledge-base-application": "0.1.7", + "@pegma/knowledge-base-contracts": "0.1.7", + "@pegma/knowledge-base-core": "0.1.7", "zod": "4.6.7" }, "scripts": { diff --git a/packages/mcp/src/mcp.ts b/packages/mcp/src/mcp.ts index 3929663..92f1e70 100644 --- a/packages/mcp/src/mcp.ts +++ b/packages/mcp/src/mcp.ts @@ -353,7 +353,7 @@ export function createKnowledgeAgentMcp( maxRequestBodySize: dispatcher.limits.maxRequestBytes, }); const server = new Server( - { name: "@pegma/knowledge-base-mcp", version: "0.1.6" }, + { name: "@pegma/knowledge-base-mcp", version: "0.1.7" }, { capabilities: { tools: {} }, // Workers prohibit the runtime code generation used by SDK-default AJV. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7544489..cf815fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,19 +24,19 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-application': - specifier: 0.1.6 + specifier: 0.1.7 version: link:packages/application '@pegma/knowledge-base-application-previous': specifier: npm:@pegma/knowledge-base-application@0.1.1 version: '@pegma/knowledge-base-application@0.1.1' '@pegma/knowledge-base-contracts': - specifier: 0.1.6 + specifier: 0.1.7 version: link:packages/contracts '@pegma/knowledge-base-core': - specifier: 0.1.6 + specifier: 0.1.7 version: link:packages/core '@pegma/knowledge-base-mcp': - specifier: 0.1.6 + specifier: 0.1.7 version: link:packages/mcp '@pegma/spine': specifier: 0.1.2 @@ -81,10 +81,10 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-contracts': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../contracts '@pegma/knowledge-base-core': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../core '@pegma/spine': specifier: 0.1.2 @@ -102,7 +102,7 @@ importers: packages/core: dependencies: '@pegma/knowledge-base-contracts': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../contracts packages/mcp: @@ -117,13 +117,13 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-application': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../application '@pegma/knowledge-base-contracts': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../contracts '@pegma/knowledge-base-core': - specifier: 0.1.6 + specifier: 0.1.7 version: link:../core zod: specifier: 4.6.7 diff --git a/test/README.md b/test/README.md index 6e270af..78d213b 100644 --- a/test/README.md +++ b/test/README.md @@ -1,5 +1,9 @@ # Public KB conformance fixtures +The current verified Knowledge Base release is +[`0.1.6`](../docs/BOOTSTRAP.md#current-verified-016-release). +The `0.1.7` source candidate remains unpublished. + The application/storage/review and retrieval/bounds/maintenance/regression suites under `tests/` share `application-stores.ts`. They target Storage Core's real memory store, its released Azure Tables adapter connected to local @@ -22,7 +26,7 @@ Upgrade tests use the dev-only exact registry alias `npm:@pegma/knowledge-base-application@0.1.1` to write real legacy records before the candidate reads them. The lockfile integrity pin matches the previously verified `0.1.1` artifact; no copied source or branch supplies this writer. -The current four-package verified KB release is `0.1.5`, and the Agent Access +The current four-package verified KB release is `0.1.6`, and the Agent Access protocol-proof pin remains `0.1.1`. Tests exercise the current working tree; changed-source gates are separate from immutable published-release evidence. @@ -101,5 +105,5 @@ by the [historical verified `0.1.2` release](../docs/BOOTSTRAP.md#historical-ver and [verified `0.1.3` release](../docs/BOOTSTRAP.md#current-verified-013-release). The later [`0.1.4` release](https://github.com/pegma-dev/knowledge-base/releases/tag/v0.1.4) is qualified. Synchronized `0.1.5` has also completed verified trusted publication -for answering read batching; see the [current receipt](../docs/BOOTSTRAP.md#current-verified-015-release). +for answering read batching; see the [retained receipt](../docs/BOOTSTRAP.md#current-verified-015-release). Changed-source and host activation gates remain open. diff --git a/tests/evidence-reports.test.ts b/tests/evidence-reports.test.ts index 2784f0f..0493f0f 100644 --- a/tests/evidence-reports.test.ts +++ b/tests/evidence-reports.test.ts @@ -6,6 +6,11 @@ import { } from "@pegma/knowledge-base-application"; import { knowledgePermissions } from "@pegma/knowledge-base-contracts"; import type { EvidenceSubmission } from "@pegma/knowledge-base-core"; +import type { + CollectionDefinition, + EntityKey, + Store, +} from "@pegma/storage-core"; import { describe, expect, it } from "vitest"; import { access, at, draft, evidence } from "../test/application-fixtures.js"; import { @@ -32,6 +37,37 @@ const capture = (promise: Promise) => (error: unknown) => ({ error }), ); +/** Hold completed real Store reads without changing their values or codecs. */ +function afterReadStore( + backing: Store, + onRead: ( + collection: string, + method: "get" | "getVersioned", + key: EntityKey, + ) => Promise, +): Store { + return { + collection(definition: CollectionDefinition) { + const target = backing.collection(definition); + return new Proxy(target, { + get(object, property) { + if (property === "get" || property === "getVersioned") + return async (key: EntityKey) => { + const saved = + property === "get" + ? await object.get(key) + : await object.getVersioned(key); + await onRead(definition.name, property, key); + return saved; + }; + const value: unknown = Reflect.get(object, property, object); + return typeof value === "function" ? value.bind(object) : value; + }, + }); + }, + }; +} + async function maximumAsciiReport( f: Awaited>, ) { @@ -280,6 +316,456 @@ for (const [backend, createStore] of storeFactories) { ).toBe(packet.input.report.details); }); + it.each(["confirmed", "rejected"] as const)( + "returns the canonical %s receipt to different current staff without changing submitter ownership", + async (status) => { + const f = await evidenceReportsFixture(await createStore()); + const packet = await f.report(); + const pending = await f.reports.read(f.reviewer, f.key(packet.ack)); + expect(pending).toMatchObject({ + ...packet.ack, + status: "pending", + submittedBy: f.agent.principalId, + confirmation: null, + }); + const decided = await f.decide(packet.ack, status); + expect(decided.ack.receipt).toBe(packet.ack.receipt); + const request = await f.verificationRequest( + decided.ack, + packet.input.evidence, + ); + if (status === "confirmed") + expect(await f.reports.verifier.verify(request)).toMatchObject({ + id: decided.ack.receipt, + verifiedBy: f.reviewer.principalId, + }); + const otherStaff = access( + "staff/second-reviewer", + f.reviewer.permissions, + ); + f.principals.set(otherStaff.principalId, otherStaff); + f.principals.delete(f.agent.principalId); + const beforeRead = await f.rows(); + const view = await f.reports.read(otherStaff, f.key(decided.ack)); + expect(view).toMatchObject({ + ...decided.ack, + status, + submittedBy: f.agent.principalId, + evidence: packet.input.evidence, + report: packet.input.report, + reportHash: pending.reportHash, + confirmation: + status === "confirmed" + ? { reviewerId: f.reviewer.principalId } + : null, + }); + expect(await f.rows()).toEqual(beforeRead); + await expect( + f.reports.read(otherStaff, { + ...f.key(decided.ack), + articleId: "article/unrelated", + }), + ).rejects.toMatchObject({ code: "report_not_found" }); + await expect( + f.reports.status(otherStaff, f.key(decided.ack)), + ).rejects.toMatchObject({ code: "report_not_found" }); + expect(await f.reports.verifier.verify(request)).toBeNull(); + expect( + await f.reports.verifier.verify({ ...request, access: otherStaff }), + ).toBeNull(); + }, + ); + + it.each(["confirmed", "pending"] as const)( + "refuses a stale staff receipt when a concurrent %s decision changes the report while its context loads", + async (transition) => { + const f = await evidenceReportsFixture(await createStore()); + const packet = await f.report(); + const original = + transition === "pending" + ? (await f.decide(packet.ack)).ack + : packet.ack; + const before = await f.reports.read(f.reviewer, f.key(original)); + expect(before).toMatchObject(original); + const gate = reportBarrier(); + f.hooks.afterContext = () => gate.wait(); + const pending = capture(f.reports.read(f.reviewer, f.key(original))); + let latest = original; + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + delete f.hooks.afterContext; + latest = (await f.decide(original, transition)).ack; + changedRows = await f.rawRows(); + } finally { + delete f.hooks.afterContext; + gate.release(); + } + expect(await pending).toMatchObject({ + error: { code: "report_changed" }, + }); + expect(await f.rawRows()).toEqual(changedRows); + const current = await f.reports.read(f.reviewer, f.key(latest)); + expect(current).toMatchObject({ ...latest, status: transition }); + if (transition === "pending") + expect(current.receipt).not.toBe(before.receipt); + }, + ); + + it.each([false, true])( + "fences a staff receipt read during reset, with drained report rows: %s", + async (drain) => { + const f = await evidenceReportsFixture(await createStore()); + const packet = await f.report(); + expect( + await f.reports.read(f.reviewer, f.key(packet.ack)), + ).toMatchObject(packet.ack); + const gate = reportBarrier(); + f.hooks.afterContext = () => gate.wait(); + const pending = capture(f.reports.read(f.reviewer, f.key(packet.ack))); + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + delete f.hooks.afterContext; + let state = await f.reports.reset(f.reviewer, { + articleId: f.articleId, + commandId: "reset-during-staff-receipt-read", + expectedLedgerEpoch: packet.ack.ledgerEpoch, + }); + if (drain) { + for (let page = 0; state.status === "resetting" && page < 4; page++) + state = await f.reports.drain(f.reviewer, { + articleId: f.articleId, + ledgerEpoch: state.ledgerEpoch, + }); + expect(state.status).toBe("active"); + expect(await f.rows()).toHaveLength(1); + } + changedRows = await f.rawRows(); + } finally { + delete f.hooks.afterContext; + gate.release(); + } + expect(await pending).toMatchObject({ + error: { code: "ledger_epoch_changed" }, + }); + expect(await f.rawRows()).toEqual(changedRows); + }, + ); + + it.each(["reset", "drain", "append"] as const)( + "fences a %s committed after the prior head guard and before report re-observation", + async (mutation) => { + const f = await evidenceReportsFixture(await createStore()); + const packet = await f.report(); + expect( + await f.reports.read(f.reviewer, f.key(packet.ack)), + ).toMatchObject(packet.ack); + const physical = await f.physicalRows(); + const head = physical.find(({ value }) => value.id === "head")!; + const report = physical.find(({ value }) => + value.id.startsWith("report:"), + )!; + const gate = reportBarrier(); + let heads = 0; + let reports = 0; + f.observed.beforeRead(async ({ collection, key }) => { + if (collection !== f.namespace) return; + if (key.id === head.key.id && ++heads === 3) await gate.wait(); + if (key.id === report.key.id && ++reports === 2) await gate.wait(); + }); + const pending = capture(f.reports.read(f.reviewer, f.key(packet.ack))); + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + f.observed.beforeRead(undefined); + expect(reports).toBe(2); + if (mutation === "append") { + const next = await f.report(); + expect(next.ack.reportId).not.toBe(packet.ack.reportId); + } else { + let state = await f.reports.reset(f.reviewer, { + articleId: f.articleId, + commandId: "reset-after-staff-read-head-guard", + expectedLedgerEpoch: packet.ack.ledgerEpoch, + }); + if (mutation === "drain") { + for ( + let page = 0; + state.status === "resetting" && page < 4; + page++ + ) + state = await f.reports.drain(f.reviewer, { + articleId: f.articleId, + ledgerEpoch: state.ledgerEpoch, + }); + expect(state.status).toBe("active"); + } + } + const after = await f.physicalRows(); + expect( + after.find(({ value }) => value.id === "head")?.version, + ).not.toBe(head.version); + const retained = after.find( + ({ value }) => value.id === report.value.id, + ); + if (mutation === "drain") expect(retained).toBeUndefined(); + else expect(retained).toEqual(report); + changedRows = await f.rawRows(); + } finally { + f.observed.beforeRead(undefined); + gate.release(); + } + expect(await pending).toMatchObject({ + error: { + code: + mutation === "append" + ? "ledger_changed" + : mutation === "reset" + ? "ledger_epoch_changed" + : expect.stringMatching( + /^(ledger_epoch_changed|report_not_found)$/u, + ), + }, + }); + expect(await f.rawRows()).toEqual(changedRows); + }, + ); + + it.each([false, true])( + "refuses reset after a completed head read while the closing report result is pending (drain=%s)", + async (drain) => { + const backing = await createStore(); + const gate = reportBarrier(); + let namespace = ""; + let headKey: EntityKey | undefined; + let reportKey: EntityKey | undefined; + let armed = false; + let reports = 0; + let heldReportVersion: string | undefined; + let lastHeadRead = Promise.resolve(); + const completedHeadVersions: (string | undefined)[] = []; + const delayed: Store = { + collection(definition: CollectionDefinition) { + const target = backing.collection(definition); + return new Proxy(target, { + get(object, property) { + if (property === "getVersioned") + return async (key: EntityKey) => { + const headRead = + armed && + definition.name === namespace && + key.partition === headKey?.partition && + key.id === headKey?.id; + let finishHead: (() => void) | undefined; + if (headRead) + lastHeadRead = new Promise((resolve) => { + finishHead = resolve; + }); + try { + const saved = await object.getVersioned(key); + if (headRead) completedHeadVersions.push(saved?.version); + if ( + armed && + definition.name === namespace && + key.partition === reportKey?.partition && + key.id === reportKey?.id && + ++reports === 2 + ) { + heldReportVersion = saved?.version; + await gate.wait(); + } + return saved; + } finally { + finishHead?.(); + } + }; + const value: unknown = Reflect.get(object, property, object); + return typeof value === "function" ? value.bind(object) : value; + }, + }); + }, + }; + const f = await evidenceReportsFixture(delayed); + const packet = await f.report(); + expect( + await f.reports.read(f.reviewer, f.key(packet.ack)), + ).toMatchObject(packet.ack); + const physical = await f.physicalRows(); + const head = physical.find(({ value }) => value.id === "head")!; + const report = physical.find(({ value }) => + value.id.startsWith("report:"), + )!; + namespace = f.namespace; + headKey = head.key; + reportKey = report.key; + armed = true; + const pending = capture(f.reports.read(f.reviewer, f.key(packet.ack))); + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + armed = false; + await lastHeadRead; + expect(completedHeadVersions.at(-1)).toBe(head.version); + expect(heldReportVersion).toBe(report.version); + let state = await f.reports.reset(f.reviewer, { + articleId: f.articleId, + commandId: "reset-after-completed-head-with-report-pending", + expectedLedgerEpoch: packet.ack.ledgerEpoch, + }); + if (drain) { + for (let page = 0; state.status === "resetting" && page < 4; page++) + state = await f.reports.drain(f.reviewer, { + articleId: f.articleId, + ledgerEpoch: state.ledgerEpoch, + }); + expect(state.status).toBe("active"); + } + const after = await f.physicalRows(); + expect( + after.find(({ value }) => value.id === "head")?.version, + ).not.toBe(head.version); + const retained = after.find( + ({ value }) => value.id === report.value.id, + ); + if (drain) expect(retained).toBeUndefined(); + else expect(retained).toEqual(report); + changedRows = await f.rawRows(); + } finally { + armed = false; + gate.release(); + } + expect(await pending).toMatchObject({ + error: { code: "ledger_epoch_changed" }, + }); + expect(await f.rawRows()).toEqual(changedRows); + }, + ); + + it.each([false, true])( + "fences owner status reset after the earlier head snapshot while its report read is pending (drain=%s)", + async (drain) => { + const gate = reportBarrier(); + let namespace = ""; + let headKey: EntityKey | undefined; + let reportKey: EntityKey | undefined; + let armed = false; + let heads = 0; + let reports = 0; + const backing = afterReadStore( + await createStore(), + async (collection, method, key) => { + if (!armed || collection !== namespace) return; + if (method === "getVersioned" && key.id === headKey?.id) heads++; + if (method === "get" && key.id === reportKey?.id && ++reports === 2) + await gate.wait(); + }, + ); + const f = await evidenceReportsFixture(backing); + const packet = await f.report(); + expect(await f.reports.status(f.agent, f.key(packet.ack))).toEqual({ + ...packet.ack, + status: "pending", + }); + const physical = await f.physicalRows(); + headKey = physical.find(({ value }) => value.id === "head")!.key; + reportKey = physical.find(({ value }) => + value.id.startsWith("report:"), + )!.key; + namespace = f.namespace; + armed = true; + const pending = capture(f.reports.status(f.agent, f.key(packet.ack))); + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + armed = false; + expect(heads).toBeGreaterThan(0); + let state = await f.reports.reset(f.reviewer, { + articleId: f.articleId, + commandId: "reset-while-owner-status-report-pending", + expectedLedgerEpoch: packet.ack.ledgerEpoch, + }); + if (drain) + for (let page = 0; state.status === "resetting" && page < 4; page++) + state = await f.reports.drain(f.reviewer, { + articleId: f.articleId, + ledgerEpoch: state.ledgerEpoch, + }); + changedRows = await f.rawRows(); + } finally { + armed = false; + gate.release(); + } + expect(await pending).toMatchObject({ + error: { code: "ledger_epoch_changed" }, + }); + expect(await f.rawRows()).toEqual(changedRows); + }, + ); + + it.each([ + { optimized: false, drain: false }, + { optimized: false, drain: true }, + { optimized: true, drain: false }, + { optimized: true, drain: true }, + ])( + "fences owner query reset during its closing current-authority await (optimized=$optimized, drain=$drain)", + async ({ optimized, drain }) => { + const f = await evidenceReportsFixture(await createStore()); + const reports = optimized + ? f.freshReports({ + authoringContext: { + getAuthoringContext: f.app.getAuthoringContext, + confirmAuthoringContext: f.app.confirmAuthoringContext, + }, + }) + : f.reports; + const packet = await f.report(); + const query = { + articleId: f.articleId, + status: { + ledgerEpoch: packet.ack.ledgerEpoch, + reportId: packet.ack.reportId, + }, + }; + expect((await reports.query(f.agent, query)).status).toEqual({ + ...packet.ack, + status: "pending", + }); + const gate = reportBarrier(); + let resolutions = 0; + f.hooks.beforeResolve = async (id) => { + if (id !== f.agent.principalId || ++resolutions !== 2) return; + delete f.hooks.beforeResolve; + await gate.wait(); + }; + const pending = capture(reports.query(f.agent, query)); + let changedRows = await f.rawRows(); + try { + await gate.reached(pending); + let state = await reports.reset(f.reviewer, { + articleId: f.articleId, + commandId: "reset-during-owner-query-current-check", + expectedLedgerEpoch: packet.ack.ledgerEpoch, + }); + if (drain) + for (let page = 0; state.status === "resetting" && page < 4; page++) + state = await reports.drain(f.reviewer, { + articleId: f.articleId, + ledgerEpoch: state.ledgerEpoch, + }); + changedRows = await f.rawRows(); + } finally { + delete f.hooks.beforeResolve; + gate.release(); + } + expect(await pending).toMatchObject({ + error: { code: "ledger_epoch_changed" }, + }); + expect(await f.rawRows()).toEqual(changedRows); + }, + ); + it.each(["confirm", "reassess"] as const)( "refuses a stale owner status when a concurrent %s changes the report after its first load", async (transition) => { @@ -389,6 +875,38 @@ for (const [backend, createStore] of storeFactories) { ...recovered, status: "pending", }); + expect(await f.reports.read(f.reviewer, f.key(recovered))).toMatchObject({ + ...recovered, + status: "pending", + }); + expect(await f.rows()).toEqual(committed); + }); + + it("reads the canonical receipt after an accepted decision loses its acknowledgement", async () => { + const f = await evidenceReportsFixture(await createStore()); + const packet = await f.report(); + const { input } = await f.decisionInput(packet.ack); + let lost = false; + f.observed.intercept(async (trace, commit) => { + const result = await commit(); + if (!lost && trace.collection === f.namespace && result.committed) { + lost = true; + throw new Error("PRIVATE_DECISION_ACK_CANARY"); + } + return result; + }); + await expect( + f.reports.decide(f.reviewer, input, "confirmed"), + ).rejects.toMatchObject(unavailable); + f.observed.intercept(undefined); + const committed = await f.rows(); + const view = await f.reports.read(f.reviewer, f.key(packet.ack)); + const recovered = await f.reports.decide(f.reviewer, input, "confirmed"); + expect(view).toMatchObject({ + ...recovered, + status: "confirmed", + confirmation: { reviewerId: f.reviewer.principalId }, + }); expect(await f.rows()).toEqual(committed); }); @@ -862,6 +1380,13 @@ for (const [backend, createStore] of storeFactories) { const reassessed = await f.decide(old.ack, "pending"); expect(reassessed.ack.reportId).toBe(old.ack.reportId); expect(reassessed.ack.receipt).not.toBe(old.ack.receipt); + expect( + await f.reports.read(f.reviewer, f.key(reassessed.ack)), + ).toMatchObject({ + ...reassessed.ack, + status: "pending", + confirmation: null, + }); expect(await f.reports.verifier.verify(stale)).toBeNull(); const beforeReplay = await f.rows(); expect( @@ -875,6 +1400,10 @@ for (const [backend, createStore] of storeFactories) { f.submit(reassessed.ack, packet.input.evidence), ).rejects.toMatchObject(kbEvidenceRefusal); const confirmed = await f.decide(reassessed.ack); + expect(confirmed.ack.receipt).toBe(reassessed.ack.receipt); + expect( + await f.reports.read(f.reviewer, f.key(confirmed.ack)), + ).toMatchObject({ ...confirmed.ack, status: "confirmed" }); await f.submit(confirmed.ack, packet.input.evidence); expect(await f.reports.verifier.verify(stale)).toBeNull(); }); @@ -1055,6 +1584,9 @@ for (const [backend, createStore] of storeFactories) { expect(state).toMatchObject({ ledgerEpoch: 2, status: "resetting" }); expect(await f.reports.reset(f.reviewer, resetInput)).toEqual(state); expect(await f.reports.verifier.verify(oldRequest)).toBeNull(); + await expect( + f.reports.read(f.reviewer, f.key(old.confirmed.ack)), + ).rejects.toMatchObject({ code: "ledger_epoch_changed" }); await expect(f.reports.report(f.agent, old.input)).rejects.toMatchObject({ code: "ledger_epoch_changed", }); @@ -1384,6 +1916,9 @@ for (const [backend, createStore] of storeFactories) { status: "confirmed", }); expect(await retained.report(f.agent, packet.input)).toEqual(packet.ack); + expect( + await retained.read(f.reviewer, f.key(confirmed.ack)), + ).toMatchObject({ ...confirmed.ack, status: "confirmed" }); const request = await f.verificationRequest( confirmed.ack, packet.input.evidence, @@ -1772,6 +2307,7 @@ for (const [backend, createStore] of storeFactories) { const view = await f.reports.read(f.reviewer, f.key(ack)); expect(view).toMatchObject({ status, + receipt: ack.receipt, reportGeneration: ack.reportGeneration, evidence: retained.report.input.evidence, report: retained.report.input.report,