document-compute.js 1.2.18 → 1.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +2 -2
  2. package/package.json +5 -4
package/README.md CHANGED
@@ -113,7 +113,7 @@ One thing #573 asks for was closed at adoption rather than built here: `Quantity
113
113
 
114
114
  Scoped to point-valued (`Quantity`) answers: every value this harness computes comes from evaluating a closed statement with no bindings, which `evaluate` cannot turn into an `Interval` (an `Interval` only ever arises by binding a symbol to one) — a genuinely interval-valued worked example (`0.87 <= cos(phi) <= 1`, #573's own illustration of interval arithmetic) has no representation in this "symbol = expression" equality grammar at all, since neither `MathExpression` nor `documents.js`'s LaTeX lowering has a compound-inequality-to-range reading, and is out of scope for this pass rather than silently mishandled.
115
115
 
116
- `src/harness/corpus.test.ts` proves the whole pipeline end to end — markdown text through `markdown-codec`'s `$$` block recognition and `documents.js`'s `lowerMarkdownMath` (the "LaTeX lowering" #794 names as the natural source of worked examples) into this harness — against a small, hand-authored starter corpus. `markdown-codec` and `documents.js` are **devDependencies only**: both sit above this package in the family's own dependency order (see the monorepo root README's package table), so neither can be a runtime dependency here without a cycle, which is exactly why this package remains "not wired into the conversion pipeline" at runtime even though its own test suite now exercises that pipeline. A large real-world corpus (the issue's own stated differentiator at scale) is not included — gathering one is a data-curation task, not a code one — but is a straightforward local addition: point a `test/corpus/` directory (gitignored, matching `pdf-codec`'s own `test:corpus` convention) at real markdown documents with worked examples and feed `readMarkdownContent` → `lowerMarkdownMath` → `runCorpus` the same way `corpus.test.ts` does.
116
+ `src/harness/corpus.test.ts` proves the whole pipeline end to end — markdown text through `markdown-codec`'s `$$` block recognition and `documents.js`'s `lowerMarkdownMath` (the "LaTeX lowering" #794 names as the natural source of worked examples) into this harness — against a small, hand-authored starter corpus. `markdown-codec` and `documents.js` are **devDependencies only**: both sit above this package in the family's own dependency order (see the monorepo root README's package table), so neither can be a runtime dependency here without a cycle. The harness itself is not test-only, though `src/index.ts` exports it as real public API (`runWorkedExampleSequence`, `collectFormulas`, `runCorpus`, `formatCorpusReport`), the same as `evaluate`/`solveFor`; what's actually true is narrower: it has no runtime consumer anywhere else in the family yet, unlike `evaluate`/`solveFor` below it, which `document-mcp`'s `compute_formula` tool does depend on directly (see Conventions). A large real-world corpus (the issue's own stated differentiator at scale) is not included — gathering one is a data-curation task, not a code one — but is a straightforward local addition: point a `test/corpus/` directory (gitignored, matching `pdf-codec`'s own `test:corpus` convention) at real markdown documents with worked examples and feed `readMarkdownContent` → `lowerMarkdownMath` → `runCorpus` the same way `corpus.test.ts` does.
117
117
 
118
118
  While building this harness's own fixtures, a real bug surfaced in `documents.js`'s LaTeX lowering: `F = m \times a` (the textbook-standard way to write almost any formula) lowers to `(F = m) \times a` rather than `F = (m \times a)`, because the lowering folds relational and arithmetic operators at the same precedence with no notion that `=` should bind loosest — filed as [ExaDev/documents.js#812](https://github.com/ExaDev/documents.js/issues/812). This package's own fixtures work around it with an explicit braced right-hand side (`F = {m \times a}`, which lowers correctly), since fixing the lowering itself is out of scope for this package.
119
119
 
@@ -131,7 +131,7 @@ Quoting the issue's own scope line directly: **this is deliberately not a CAS in
131
131
  - Worker-isomorphic (see the [family-wide convention](https://github.com/ExaDev/documents.js/blob/main/README.md#conventions)): runtime `src/` must not import `node:*`, a bare Node builtin, or use the `Buffer` global — enforced by a `no-restricted-imports`/`no-restricted-globals` ESLint rule and exercised in CI by running a test suite inside an actual `workerd` isolate (`pnpm test:workers`). Exact-rational arithmetic is plain `BigInt`, never `node:crypto` or any other Node-only primitive, precisely so this holds.
132
132
  - Only `src/index.ts` may be named `index.*` — a custom ESLint rule (`local/no-non-barrel-index`) rejects any other module using an `index` basename, since that would be a hidden entry point the `exports` map in `package.json` doesn't advertise.
133
133
  - Failure is always a thrown, named `Error` subclass (`compute/errors.ts`), never a `{ ok, error }` result wrapper — matching `document-schema.js`'s `schema-io.ts` and `archive-codec`'s own error classes rather than inventing a second convention for this package alone.
134
- - Not wired into the conversion pipeline. This package is a standalone evaluator: it is not a dependency of `documents.js`, `document-cli`, `document-mcp`, or `web`, and adding it as one is a separate, deliberate decision for whichever of those surfaces first needs a document's formula actually computed.
134
+ - Wired into `document-mcp` since [ExaDev/documents.js#928](https://github.com/ExaDev/documents.js/issues/928): its `compute_formula` tool is a real runtime dependent, reading a document's embedded formulas and evaluating each through `evaluate()`. Still not a dependency of `documents.js`, `document-cli`, or `web` this package sits above `document-schema.js` alone in the family's own dependency order, and `document-mcp` was the first surface with a natural, agent-facing need for a document's formula actually computed; wiring it into any further surface remains a separate, deliberate decision for that surface.
135
135
  - Release, CI, and commit-message conventions are all workspace-wide, not package-local — see the [monorepo root README](../../README.md#releases) for the mechanism (topological per-package `semantic-release` via `@exadev/semantic-release-workspace`, OIDC trusted npm publishing, and the post-release republish/attestation jobs).
136
136
 
137
137
  ## Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-compute.js",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "description": "Units-typed, tree-walking evaluator for document-schema.js's MathExpression -- exact-rational unit conversion, interval arithmetic, and bisection/Newton numeric solve-for, the compute package for the documents.js family.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -58,6 +58,7 @@
58
58
  "_typecheck:attw": "attw --pack",
59
59
  "test": "turbo run _test",
60
60
  "_test": "vitest run",
61
+ "_test:coverage": "vitest run --coverage",
61
62
  "test:watch": "vitest",
62
63
  "test:workers": "turbo run _test:workers",
63
64
  "_test:workers": "vitest run --config vitest.workers.config.ts",
@@ -65,16 +66,16 @@
65
66
  },
66
67
  "packageManager": "pnpm@11.6.0",
67
68
  "dependencies": {
68
- "document-schema.js": "^5.6.0"
69
+ "document-schema.js": "^6.0.0"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@arethetypeswrong/cli": "^0.18.5",
72
73
  "@cloudflare/vitest-pool-workers": "^0.20.1",
73
74
  "@types/node": "^26.1.2",
74
- "documents.js": "^6.5.2",
75
+ "documents.js": "^7.0.0",
75
76
  "eslint": "^10.8.0",
76
77
  "husky": "^9.1.7",
77
- "markdown-codec": "^6.1.6",
78
+ "markdown-codec": "^6.1.7",
78
79
  "publint": "^0.3.21",
79
80
  "tsdown": "^0.22.13",
80
81
  "turbo": "^2.10.8",