Skip to content

Add @pretextbook/schema package with upstream change detection#163

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/implement-pretext-schema-storage
Draft

Add @pretextbook/schema package with upstream change detection#163
Copilot wants to merge 2 commits intomainfrom
copilot/implement-pretext-schema-storage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

Multiple packages need PreTeXt schema data for completions, validation, etc. Previously each package maintained its own copy; this introduces a shared @pretextbook/schema package as the canonical source.

New packages/schema package

  • src/types.tsPretextSchema, PretextSchemaElementChildren, PretextSchemaElement (with optional description for future metadata beyond the official schema)
  • src/schema.ts — Generated pretextDevSchema from pretext-dev.rng; includes all elements with allowed child elements and attributes
  • scripts/generate-schema.mjs — RNG → TypeScript conversion (consolidated from the completions package)
import { pretextDevSchema, type PretextSchema } from "@pretextbook/schema";

pretextDevSchema.elementChildren["book"].elements; // ["chapter", "backmatter", ...]

packages/completions update

  • default-dev-schema.ts replaced with a single re-export from @pretextbook/schema — removes ~9,400 lines of duplication while keeping defaultDevSchema as a backwards-compatible alias
  • Schema generation scripts removed from completions; now owned by the schema package
  • @pretextbook/schema: "*" added as a workspace dependency

GitHub Actions

  • check-pretext-schema.yml — Weekly (+ manual) workflow; SHA-256-diffs the stored pretext-dev.rng against upstream and files a schema-update-labeled issue when a change is detected
  • publish-schema.yml — Manual publish workflow for @pretextbook/schema to npm (mirrors the existing completions publish pattern)

Root-level

  • refresh:schemas script now invokes packages/schema/scripts/generate-schema.mjs
  • tsconfig.json adds packages/schema to project references

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.nx.app
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./bin/post-install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement a package that stores the PreTeXt schema as json or typescript</issue_title>
<issue_description>A number of the other packages use information about the pretext schema, to offer completion suggestions, or eventually to validate a pretext document. A version of the schema should be maintained here that all these packages can use.

I will likely want to add extra information, like short descriptions, that aren't part of the official schema. But there should be an action to watches the pretext repository and makes an issue whenever there is a change to the schema so this can be updated.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ge detection

Co-authored-by: oscarlevin <6504596+oscarlevin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add package to store PreTeXt schema as JSON or TypeScript Add @pretextbook/schema package with upstream change detection Mar 18, 2026
Copilot AI requested a review from oscarlevin March 18, 2026 18:09
@oscarlevin oscarlevin requested a review from Copilot March 18, 2026 19:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new shared @pretextbook/schema package to centralize the generated PreTeXt dev schema data (from pretext-dev.rng), and updates @pretextbook/completions to consume it instead of maintaining a duplicated generated schema file. It also adds GitHub Actions workflows to detect upstream schema changes and to publish the schema package.

Changes:

  • Added packages/schema with types, generated schema data, and an RNG→TS generation script.
  • Updated packages/completions to re-export the schema from @pretextbook/schema and removed its schema-refresh/build wiring.
  • Added workflows for weekly upstream schema change detection and manual schema package publishing; updated root scripts/tsconfig references accordingly.

Reviewed changes

Copilot reviewed 14 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tsconfig.json Adds packages/schema to TS project references.
packages/schema/tsconfig.json Introduces TS config for the schema package.
packages/schema/tsconfig.lib.json Adds library build config for schema package.
packages/schema/src/types.ts Defines exported schema-related TypeScript types.
packages/schema/src/index.ts Re-exports public API from types and generated schema.
packages/schema/src/schema.ts Adds generated pretextDevSchema data (large generated file).
packages/schema/scripts/generate-schema.mjs Adds schema generation script from RNG to TS.
packages/schema/README.md Documents the new package and update process.
packages/schema/project.json Adds Nx targets for build/typecheck/refresh-schema.
packages/schema/package.json Adds schema package metadata and scripts.
packages/completions/src/default-dev-schema.ts Replaces huge generated schema with re-export from new package.
packages/completions/scripts/generate-default-schema.mjs Deprecates old generator and delegates to schema generator.
packages/completions/project.json Removes completions’ schema refresh target/dependency.
packages/completions/package.json Drops schema scripts and adds dependency on @pretextbook/schema.
package.json Updates refresh:schemas to run the new schema generator.
package-lock.json Adds workspace link for @pretextbook/schema and updates dependency graph.
.github/workflows/publish-schema.yml Adds manual publish workflow for schema package.
.github/workflows/check-pretext-schema.yml Adds weekly/manual upstream change detection and issue filing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

};
// Re-exported from @pretextbook/schema for backwards compatibility.
// The canonical schema data lives in packages/schema/src/schema.ts.
export { pretextDevSchema as defaultDevSchema } from "@pretextbook/schema";
Comment on lines +9 to +15
"build": {
"executor": "nx:run-commands",
"dependsOn": ["refresh-schema", "^build"],
"options": {
"cwd": "packages/schema",
"command": "tsc --build tsconfig.lib.json"
},
Comment on lines +17 to +28
"main": "./src/index.ts",
"module": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts",
"default": "./src/index.ts"
}
},
"files": [
"src/**/*",
Comment on lines +46 to +55
## Updating the Schema

The schema data in `src/schema.ts` is generated automatically from the official PreTeXt RelaxNG schema. To regenerate it:

```bash
npm run fetch:dev-schema # Download latest pretext-dev.rng
npm run generate:schema # Regenerate src/schema.ts
```

A GitHub Actions workflow (`check-pretext-schema.yml`) runs weekly to detect upstream schema changes and file an issue when the schema should be updated.
Comment on lines +82 to +87
1. Run \`npm run refresh:schemas\` from the workspace root to download the latest schema and regenerate \`packages/schema/src/schema.ts\`.
2. Review the diff to understand what changed in the schema.
3. Update any element descriptions or extra metadata in \`packages/schema/src/schema.ts\` as needed.
4. Commit the updated \`extension/assets/schema/pretext-dev.rng\` and \`packages/schema/src/schema.ts\`.

This issue was created automatically by the [check-pretext-schema workflow](https://github.com/${{ github.repository }}/actions/workflows/check-pretext-schema.yml)."
},
"scripts": {},
"dependencies": {
"@pretextbook/schema": "*",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a package that stores the PreTeXt schema as json or typescript

3 participants