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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Summary

Describe the problem, resulting behavior, and task scope.

## Compatibility and authority

Describe public API, collection audience, approval/evidence, and private-data
impacts. Explain any new host prerequisites or artifact/release consequences.

## Validation

- [ ] `pnpm run format:check`
- [ ] `pnpm run check`
- [ ] `pnpm test`
- [ ] `pnpm run release:check`
- [ ] Current-head Node 22/24, review, and security gates
- [ ] No private host internals or real customer data
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
concurrency:
group: ci-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
validate:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [22, 24]
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
version: 10.34.5
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check formatting
run: pnpm run format:check
- name: Check types
run: pnpm run check
- name: Run tests
run: pnpm test
- name: Check package artifacts
run: pnpm run release:check
34 changes: 34 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CodeQL

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "27 8 * * 1"

permissions:
contents: read
security-events: write
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved

concurrency:
group: codeql-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
analyze:
name: Analyze JavaScript and TypeScript
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
with:
languages: javascript-typescript
- name: Build
uses: github/codeql-action/autobuild@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
- name: Analyze
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ dist

# pnpm
.pnpm-store
.release/

# yarn v3
.pnp.*
Expand Down
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
coverage/
artifacts/
pnpm-lock.yaml
52 changes: 52 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Working in this repository

Knowledge Base is a standalone MIT Pegma component. Optimize for a fresh agent
context: small typed contracts, explicit composition, and meaningful public-API
tests. The approved scope is the [Support Desk enhancement plan](https://github.com/pegma-dev/support-desk/blob/main/docs/KNOWLEDGE_AI_PLAN.md).

## Boundaries

- Contracts and core own collection policy, immutable article revisions,
validation/evidence bindings, approval, publication, and retirement.
- KB-01 is pure domain work. Storage, authorized services, retrieval, API/MCP,
and host interfaces are later tasks; do not create their packages early.
- 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.
- Reuse Spine's identity/time types. Pin exact released Pegma versions. A host
cannot consume an unpublished package through a branch, copied source, or a
local path as a production release substitute.
- Collections own all access policy. Articles inherit it without ACL overrides.
Portal visibility and approved bot-answer audiences are independent; private
is the default. Public access requires an explicit reviewed policy change.
- Approval binds exact content, revision, audience/policy, applicability,
validation policy, and evidence. Edits and changed authority invalidate it.
A `passed` string or claimed runner identity does not authenticate evidence.
- Core transitions are not an authorization boundary. The later application
must authenticate/authorize the actor, attestations, and current resources.
- Base packages require no Support Desk, GitHub, model, framework, HTTP, or
provider SDK. Evidence is data; never execute code or fetch submitted URLs.
- Constrain content and links; host renderers must disable executable content
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.
- 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 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.

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.
See [release operations](docs/RELEASING.md); first publication and external
trusted-publisher configuration are separate maintainer operations.

## Reading order

Read this file, the root README, then the owning package README. The public
enhancement plan defines KB-01 through KB-05. Give a worker one task and an
explicit file ownership boundary; do not revert another worker's edits.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Knowledge Base

A standalone MIT Pegma component for product documentation and support knowledge.
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: KB-01 implements contracts and pure domain transitions.
> The packages are unpublished. Authorized persistence, retrieval, API/MCP,
> and customer/staff interfaces are later tasks. This repository is not yet an
> operational knowledge-base service or a production dependency.

| Package | Scope |
| ----------------------------------------------------------------- | ------------------------------------------------------ |
| [`@pegma/knowledge-base-contracts`](packages/contracts/README.md) | Collection, article, evidence, and approval vocabulary |
| [`@pegma/knowledge-base-core`](packages/core/README.md) | Pure validation and lifecycle transitions |

Collections default to private and independently specify portal and bot-answer
audiences. Articles inherit collection policy. Staff approval binds the exact
revision, content, collection policy, applicability, validation requirements,
and evidence. A revised guide requires fresh review; prior publication never
authorizes edited content.

Core transitions accept explicit inputs and return new values. They do not
authenticate a runner or staff member, enforce host roles, fetch evidence URLs,
or execute guide steps. Later application services must enforce current
Authorization Core permissions and authenticated attestation boundaries.
Local agents will test guides against authorized staging and submit evidence
through the later API/MCP adapter.

Develop on Node 22 or 24 with pnpm 10.34.5:

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

The npm and pnpm workspace declarations deliberately name the same two source
packages: pnpm links them for development, while npm supplies artifact packing.
The release check installs both tarballs in a consumer outside either workspace
to verify dependency resolution without source links.

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.
Its [P-00 handoff](https://github.com/pegma-dev/support-desk/pull/33) records
source/registry baselines, synthetic acceptance cases, and open activation
prerequisites. These two launch hosts use separate stores and policies; the
packages do not introduce a shared tenant control plane.

Read [AGENTS.md](AGENTS.md) before changing code and
[release operations](docs/RELEASING.md) before preparing artifacts. Merging
source does not publish a package. Each new npm name needs the maintainer's
first publication and trusted-publisher setup before hosts can consume it.
95 changes: 95 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Release operations

## KB-01 status

`@pegma/knowledge-base-contracts` and `@pegma/knowledge-base-core` are prepared
at synchronized version `0.1.0`. Both package names are unpublished. KB-01
establishes packaging checks and the release handoff; it does not publish,
create tags/releases, configure credentials, or enable a publish workflow.

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:

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

`release:check` packs contracts and then core using npm. Each package's
`prepack` builds its own output, so a package cannot silently ship a stale
distribution. The checker verifies:

- synchronized stable versions, exact internal/Spine pins, ESM/public metadata,
and the two declared runtime/type entry points;
- a package-local README and MIT LICENSE, a build-on-prepack script, and
exclusion of `src/**/*.test.ts` from compilation;
- npm's artifact inventory containing only package metadata, README, LICENSE,
and JavaScript/declaration output and maps under `dist`, with compiled tests
excluded and both entry-point files present;
- the actual tarball bytes against npm's reported SHA-1 and SHA-512 integrity;
- an isolated consumer installation of both tarballs and successful ESM
imports of both public packages.

The consumer disables install scripts, audit, and funding requests and obtains
released external dependencies from the public npm registry. It has no workspace
links. The checker locates `npm-cli.js` and invokes it with Node directly on
Windows and Unix; it does not interpolate commands through a shell. Temporary
files are removed only after checking their resolved directory is the generated
child of the system temporary root. No user npm configuration is inspected or
printed.

To keep the same verified tarballs for maintainer inspection:

```sh
pnpm run release:pack
```

This runs the same checks, then writes a new `.release/knowledge-base-*`
directory containing the two tarballs and `manifest.json` with their inventory
and integrity values. Existing artifact directories are preserved. These files
are local preparation artifacts, not proof of a released version or provenance.
The checker does not verify a source tag, main ancestry, registry publication,
or trusted-publisher configuration. Those are release prerequisites below.

## Maintainer prerequisites before first publication

These operations remain pending and must be recorded when completed:
Recheck npm's current [trusted-publishing guidance](https://docs.npmjs.com/trusted-publishers/)
when implementing the release workflow; this checklist records the Pegma
release procedure, not proof that external publisher settings exist.

- [ ] Confirm package-name ownership and organization publishing permissions.
- [ ] Complete KB-05's application/adapter and dual-store release criteria for
any additional packages being advertised; 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,
and artifact check to pass.
- [ ] Configure protection for immutable `v*` tags and approved release signers.
- [ ] Prepare and verify the exact artifacts from a protected signed annotated
`vX.Y.Z` tag whose commit is already on `origin/main`.
- [ ] The maintainer performs the new package names' one-time manual 2FA
publication of those exact verified tarballs. Choose and document the
bootstrap/first advertised release procedure before this operation.
- [ ] Configure npm trusted publishers for this repository, the reviewed future
publish workflow, and its protected publishing environment.
- [ ] Establish the future workflow: unprivileged signature/main/gate/pack
preparation, followed by a minimal environment-approved OIDC publish job
receiving only the exact prepared artifacts.
- [ ] Verify registry versions, tarball integrity, provenance, and a clean
public consumer installation before marking the packages available.

The first-publication procedure is a maintainer operation, not a command hidden
in CI. Do not add an npm token or token-based fallback to this repository.
Merging a PR does not publish. Later releases must use the protected signed
annotated tag and trusted-publisher path, preserve published version immutability,
and recover partial publication by verifying identical existing artifacts rather
than overwriting a version. Define that workflow in the release task before
enabling publication.
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "knowledge-base",
"version": "0.0.0",
"private": true,
"description": "Composable product documentation and support knowledge for Pegma hosts.",
"license": "MIT",
"type": "module",
"engines": {
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
"node": ">=22"
},
"workspaces": [
"packages/*"
],
"scripts": {
"build": "tsc -b",
"check": "tsc -b --pretty false && tsc -p tsconfig.test.json --pretty false",
"clean": "tsc -b --clean",
"format": "prettier --write .",
"format:check": "prettier --check .",
"test": "pnpm run build && vitest run",
"release:check": "node scripts/release-packages.mjs check",
"release:pack": "node scripts/release-packages.mjs pack"
},
"devDependencies": {
"@types/node": "26.6.6",
"prettier": "3.9.10",
"typescript": "7.0.2",
"vitest": "5.0.5"
},
"packageManager": "pnpm@10.34.5"
}
21 changes: 21 additions & 0 deletions packages/contracts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Pegma

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading