Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impacts. Explain any new host prerequisites or artifact/release consequences.
- [ ] `pnpm run format:check`
- [ ] `pnpm run check`
- [ ] `pnpm test`
- [ ] `pnpm example`
- [ ] `pnpm run release:check`
- [ ] Current-head Node 22/24, review, and security gates
- [ ] No private host internals or real customer data
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
validate:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand All @@ -40,5 +41,7 @@ jobs:
run: pnpm run check
- name: Run tests
run: pnpm test
- name: Run synthetic composition
run: pnpm example
- name: Check package artifacts
run: pnpm run release:check
15 changes: 14 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ tests. The approved scope is the [Support Desk enhancement plan](https://github.
application services. KB-03 extends the application with bounded retrieval,
authoritative confirmation, and repair; it adds no package. API/MCP and live
host interfaces remain later tasks; do not create their packages early.
- Independent partial KB-05 source preparation adds local D1 conformance and
a public synthetic composition. It does not complete KB-04 credentials or
the full KB-05 release/publication task. All three packages remain unpublished.
- Never implement a database, authorization role model, identity/session/token
system, audit log, request limiter, or durable scheduler here. Compose the
corresponding Pegma package in the owning later task.
Expand Down Expand Up @@ -46,15 +49,23 @@ tests. The approved scope is the [Support Desk enhancement plan](https://github.
and raw HTML. Staff evidence/provenance never enters customer or bot DTOs.
- Use fictional fixtures only. Commercial host internals, credentials, customer
content, and operational configuration stay in their owning private systems.
- D1 consumer fixtures use the released adapter with a real local Miniflare
binding, not a fake port or cast. Each factory call gets an isolated database;
register asynchronous disposal before initialization and clean up failures.
Keep native workers/timeouts bounded. Fixture contexts/receipts are synthetic
trust inputs, not live authentication or staging proof.
- Never write literal control bytes into source. Use escaped forms and verify
bytes after tool-assisted edits.

## Workflow

Work on a `claude/*` branch and open a PR. Required checks are
`pnpm run format:check`, `pnpm run check`, `pnpm test`, and
`pnpm run format:check`, `pnpm run check`, `pnpm test`, `pnpm example`, and
`pnpm run release:check`, on Node 22 and 24. Run the applicable review/security
checks for the current head. Do not bypass pending, skipped, or failing gates.
Repository development and the TypeScript example require Node 22.6.0+ or 24.
The root engine floor covers the example's `--experimental-strip-types` flag;
published package engines remain `>=22`, and CI tracks current Node 22/24.

Each published package needs its own README and MIT LICENSE, a build-on-prepack
script, and compiled-test exclusion. Merging source does not publish packages.
Expand All @@ -71,3 +82,5 @@ durable operations and [host composition](docs/HOST_COMPOSITION.md) before
changing authorization, verifier, replay, or DTO boundaries.
For KB-03, read [retrieval](docs/RETRIEVAL.md) and the declared projection
layout before changing query work, citations, or repair.
For partial KB-05, read [source preparation](docs/SOURCE_PREPARATION.md) before
changing local D1 fixtures, synthetic composition, or release-readiness claims.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ and exact publication approval. It requires no GitHub connection or AI provider.
> Development status: KB-01 provides contracts and pure domain transitions;
> KB-02 adds authorized application/persistence source, and KB-03 extends that
> application with bounded retrieval and repair. Implementation and repository
> gates determine completion. All three packages are unpublished. API/MCP and
> live customer/staff interfaces remain later tasks. This repository is not yet
> an operational hosted KB or a production dependency.
> gates determine source evidence. Independent partial KB-05 preparation adds
> local D1 conformance and a public synthetic example. KB-04 credentials and the
> full KB-05 release task remain unfinished. All three packages are unpublished
> at `0.1.0`. API/MCP and live customer/staff interfaces remain later tasks. This
> repository is not yet an operational hosted KB or a production dependency.

| Package | Scope |
| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -49,20 +51,30 @@ bot-answer uses have separate safe citations; bot-only knowledge does not
grant an article browse capability. Read [retrieval](docs/RETRIEVAL.md) for
physical work/source budgets, whole-article token accounting, and repair.

Develop on Node 22 or 24 with pnpm 10.34.5:
Partial [source preparation](docs/SOURCE_PREPARATION.md) runs shared public KB
conformance against memory, local Azurite, and real local Miniflare D1 through
the released D1 adapter. The [synthetic composition](examples/composition/README.md)
demonstrates the public author/test/review/publish/retrieve flow with fictional
trust inputs. Local emulators and that example establish neither live Workers
deployment nor scoped API/MCP credentials, publication, or host acceptance.

Develop on Node 22.6.0+ or 24 with pnpm 10.34.5:

```sh
pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
pnpm test
pnpm example
pnpm run release:check
```

The npm and pnpm workspace declarations deliberately name the same source
packages: pnpm links them for development, while npm supplies artifact packing.
The release check installs all three tarballs in a consumer outside either workspace
to verify dependency resolution without source links.
Frozen installation permits the pinned native `workerd` install script only;
test workers/timeouts and per-factory D1 disposal remain bounded.

The [approved enhancement plan](https://github.com/pegma-dev/support-desk/blob/main/docs/KNOWLEDGE_AI_PLAN.md)
defines KB-01 through KB-05 and the later Support Desk/host integrations.
Expand Down
10 changes: 10 additions & 0 deletions docs/HOST_COMPOSITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ not an HTTP server, an identity system, or an operational MCP endpoint.
See [declared collections](COLLECTIONS.md) for the required
layout, CAS, admission, and replay design.

Independent partial KB-05 [source preparation](SOURCE_PREPARATION.md) adds
shared memory/Azurite/local-D1 conformance and a
[public synthetic composition](../examples/composition/README.md). The D1
fixture passes a real Miniflare binding directly to the released
`@pegma/storage-cloudflare-d1@0.4.1` adapter with isolated per-factory cleanup.
It is local consumer evidence, not a deployed Workers binding or production
acceptance. The example's resolved contexts and receipt registry stand in for
trusted host facts; they authenticate no real browser, agent, or staging run.
KB-04's credential/client flow and full KB-05 publication remain unfinished.

The host owns identity verification, scoped local-agent credentials, current
authorization resolution, browser/transport protections, store construction,
clock/logger, trusted attestation verification, source-resource authorization,
Expand Down
16 changes: 13 additions & 3 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ domain, authorized application, and bounded retrieval source plus packaging
checks; their repository gates determine task completion. They do not publish, create tags/releases,
configure credentials, or enable a publish workflow.

Independent partial KB-05 [source preparation](SOURCE_PREPARATION.md) adds the
local Miniflare D1 consumer fixture, shared three-backend conformance, and a
public synthetic example. This is not completion of KB-04 or full KB-05. No
package is added or published; all three remain unpublished at `0.1.0`.

Hosts must wait for an exact public registry release. Git branches, copied
source, local paths, and unpublished production tarballs are not substitutes.
The temporary tarball consumer below is a packaging test only.

## Artifact checks

Run the repository gate on Node 22 and 24 with the pinned pnpm version:
Use Node 22.6.0+ or 24 for the repository gate and source example, with the
pinned pnpm version. CI continues to track current Node 22 and 24; published
package engines remain `>=22`.

```sh
pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
pnpm test
pnpm example
pnpm run release:check
```

Expand Down Expand Up @@ -70,8 +78,10 @@ release procedure, not proof that external publisher settings exist.

- [ ] Confirm package-name ownership and organization publishing permissions.
- [ ] Complete KB-05's advertised package/adapter and dual-store release
criteria. KB-02/KB-03 memory/Azurite evidence does not establish the later D1
consumer fixture, MCP client flow, or either host's production readiness.
criteria. Partial source preparation supplies a real local D1 consumer
fixture and synthetic composition subject to current-head gates. It does
not establish KB-04's authenticated real-client flow, live Workers/host
acceptance, or complete package/bootstrap/publication readiness.
Do not publish empty packages.
- [ ] Merge reviewed release source and exact version/pin changes to protected
`origin/main`; require every current-head review, test, build, security,
Expand Down
154 changes: 154 additions & 0 deletions docs/SOURCE_PREPARATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# KB-05 source preparation

## Scope and readiness

This is an independent, partial KB-05 source-preparation slice. It adds a real
local D1 consumer fixture and a public synthetic composition example over the
existing contracts/core/application packages. It does not finish KB-04 or the
full KB-05 release task. All three KB packages remain unpublished at source
version `0.1.0`.

| Evidence area | This source slice | Separate remaining proof |
| ---------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
| Storage consumer | Shared public KB suites on memory, local Azurite, and local Miniflare D1 | Production Azure/Workers configuration, operations, and host acceptance |
| Composition | Runnable fictional author/evidence/review/publication/retrieval flow | Real host identity, staging verification, scoped API/MCP credentials, and UI |
| Artifacts | Existing three-package pack/import checks | First publication, trusted-publisher setup, registry integrity/provenance, and released consumers |
| Task readiness | Current-head repository gates establish this slice's evidence | KB-04 credential/client proof and all remaining KB-05 exit criteria |

No test counts or pass verdicts are implied by this document. Record verified
current-head gate results before treating the source slice as validated.
Local emulator and fixture results are not production or live Workers proof.

## Pinned local D1 consumer

The source dependency snapshot was verified on **2026-11-07**. These are exact
repository pins, not a claim about the latest available versions:

| Dependency/configuration | Pin |
| -------------------------------- | ---------------------------------------- |
| Released D1 adapter | `@pegma/storage-cloudflare-d1@0.4.1` |
| Storage contract | `@pegma/storage-core@0.4.0` |
| Local emulator | `miniflare@4.20260730.0` |
| Miniflare declaration dependency | `@cloudflare/workers-types@5.20260730.1` |
| Locked native runtime | `workerd@1.20260730.1` (transitive) |
| Local compatibility date | `2026-07-28` |
| Repository toolchain | Node 22.6.0+ or 24, `pnpm@10.34.5` |

The source example uses `node --experimental-strip-types`, introduced in
[Node 22.6.0](https://nodejs.org/en/blog/release/v22.6.0). The root development
engine floor is therefore `>=22.6.0`. Published package engines remain `>=22`;
the CI matrix continues to track current Node 22 and 24.

[test/d1.ts](../test/d1.ts) obtains Miniflare's real `getD1Database("DB")`
binding and passes it directly to the released `createCloudflareD1Store`.
It uses no handwritten SQL/HTTP facade, fake D1 binding, or type cast to hide
an incompatible adapter port. Miniflare owns the local D1 execution and native
runtime; the KB still owns no database implementation. Cloudflare types are
test tooling, not a new public core dependency.

Each factory invocation creates a fresh Miniflare runtime and randomly named
D1 database, even when a test asks for multiple stores. It uses loopback with
an ephemeral port, `cf: false`, and `d1Persist: false`; no live Cloudflare
account or persistent production database participates.

The fixture registers Vitest's `onTestFinished` cleanup before native
construction or binding lookup. A shared memoized asynchronous disposal path
handles both initialization failure and normal completion; cleanup failures
remain visible, including combined setup/cleanup failure. Calling this helper
outside a Vitest test fails before a native runtime can be left behind.
[D1 isolation cases](../tests/d1-isolation.test.ts) exercise factory isolation.

## Shared conformance and bounded execution

[test/application-stores.ts](../test/application-stores.ts) supplies the same
store-factory surface to public KB application, storage, retrieval, and
regression suites. Memory uses Storage Core's real memory adapter; Azurite
uses the released Azure Tables adapter and unique table names; D1 uses the
released D1 adapter above. Tests call public application entry points and the
actual declared codecs. No parallel KB repository or authorization engine is
introduced. [test/README.md](../test/README.md) records fixture usage.

Memory stores are fresh per factory call. Azurite's emulator lifecycle and
guarded temporary-directory cleanup remain in
[test/azurite.ts](../test/azurite.ts). D1's per-factory native disposal is
separate from that global emulator lifecycle. Do not reuse a D1 database for
convenience or omit asynchronous cleanup on a failing test.

Native execution has explicit repository bounds:

| Control | Bound |
| ----------------- | ----------------------------- |
| Vitest workers | At most 4 |
| Test timeout | 180 seconds |
| Hook timeout | 30 seconds |
| D1 disposal hook | 30 seconds |
| CI validation job | 30 minutes per Node 22/24 job |

Windows development measurements include local Node-to-workerd RPC and setup
overhead across the real adapter's operations. These bounded budgets allow
that native conformance work; assertions, cleanup, and full current-head gates
still establish correctness. Local elapsed time is not production D1 latency
or a performance certification.

The frozen pnpm workspace explicitly permits only the pinned `workerd`
dependency's install script through `onlyBuiltDependencies`. It does not
authorize unrelated dependency scripts. New workspaces use the normal pinned
installation path:

```sh
pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
pnpm test
pnpm example
pnpm run release:check
```

The CI workflow runs those checks, including the synthetic example, on Node
22 and 24. A local run does not substitute for required current-head CI or
reviews. Adapter conformance also does not certify production throughput,
retention, backups, network protections, or distributed deployment behavior.

## Public synthetic composition

[examples/composition](../examples/composition/README.md) is repository-owned
fictional source. `createExampleComposition` accepts a host Store (memory by
default), and `runCompleteExampleFlow` exercises the public KB services. The
example imports no test-only helper and contains no commercial host routes,
credentials, customer data, or operational topology.

Its resolved access contexts are synthetic trusted inputs, not authenticated
browser/API requests. A private receipt registry binds immutable serialized
synthetic-run facts to the exact principal, article revision, whole evidence
submission, and governance configuration. The verifier returns a fixed
synthetic attester only after lookup and exact comparison; it does not echo
caller-supplied `passed` or runner identity as proof. This demonstrates the
host trust seam, not a production runner, OAuth server, signature scheme, or
live staging test.

Source checks, review/publication, audience separation, and safe retrieval
still pass through the real application. The example does not establish real
external source-reference eligibility. One UTF-8 byte counts as one fixture
token; that is not a provider tokenizer or billing measurement. No model
provider or GitHub connection is required.

[tests/composition.test.ts](../tests/composition.test.ts) runs the same public
flow through all three store factories and defines negative cases for tampered
evidence, author publication authority, private-data exclusion, bot-only
citations, and retirement with old projection hints. Current-head gate results
remain the evidence of execution.

## Remaining gates

KB-04 must still establish the real scoped/revocable/audience-bound author
credential and protected-resource/client flow. Manually supplied fixture
contexts do not close that prerequisite. The optional API/MCP contract and
real local-client author/test/evidence loop require their own task evidence.

The full KB-05 release candidate still needs its advertised package/adapter
and client criteria, reviewed bootstrap/trusted-publisher configuration, exact
registry publication, artifact/provenance verification, and released consumer
checks. See [release operations](RELEASING.md). No empty adapter package,
release tag, publication, or host activation is created by this source slice.
Hosts must wait for exact released artifacts rather than adopting branches,
copied source, local paths, or unpublished production tarballs.
Loading
Loading