@danielsimonjr/mathts-workbook 0.4.0 → 0.4.1

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 (55) hide show
  1. package/README.md +247 -247
  2. package/dist/{chunk-ZVCYWKM5.js → chunk-JM3ZAYJC.js} +1 -1
  3. package/dist/cli.d.ts +18 -19
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +1 -1
  6. package/dist/contract.d.ts +16 -0
  7. package/dist/contract.d.ts.map +1 -0
  8. package/dist/doc.d.ts +29 -0
  9. package/dist/doc.d.ts.map +1 -0
  10. package/dist/edit.d.ts +44 -0
  11. package/dist/edit.d.ts.map +1 -0
  12. package/dist/executor.d.ts +98 -0
  13. package/dist/executor.d.ts.map +1 -0
  14. package/dist/formatter.d.ts +9 -0
  15. package/dist/formatter.d.ts.map +1 -0
  16. package/dist/fs-atomic.d.ts +11 -0
  17. package/dist/fs-atomic.d.ts.map +1 -0
  18. package/dist/graph.d.ts +41 -0
  19. package/dist/graph.d.ts.map +1 -0
  20. package/dist/html.d.ts +43 -0
  21. package/dist/html.d.ts.map +1 -0
  22. package/dist/index.d.ts +18 -501
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +1 -1
  25. package/dist/introspect.d.ts +29 -0
  26. package/dist/introspect.d.ts.map +1 -0
  27. package/dist/ipynb.d.ts +24 -0
  28. package/dist/ipynb.d.ts.map +1 -0
  29. package/dist/markdown.d.ts +13 -0
  30. package/dist/markdown.d.ts.map +1 -0
  31. package/dist/parser.d.ts +47 -0
  32. package/dist/parser.d.ts.map +1 -0
  33. package/dist/pdf.d.ts +12 -0
  34. package/dist/pdf.d.ts.map +1 -0
  35. package/dist/rpc.d.ts +45 -0
  36. package/dist/rpc.d.ts.map +1 -0
  37. package/dist/run-worker.d.ts +2 -2
  38. package/dist/run-worker.d.ts.map +1 -0
  39. package/dist/session.d.ts +68 -0
  40. package/dist/session.d.ts.map +1 -0
  41. package/dist/svg-math.d.ts +19 -0
  42. package/dist/svg-math.d.ts.map +1 -0
  43. package/dist/svg.d.ts +9 -0
  44. package/dist/svg.d.ts.map +1 -0
  45. package/dist/tex.d.ts +17 -0
  46. package/dist/tex.d.ts.map +1 -0
  47. package/dist/timeout-runner.d.ts +22 -0
  48. package/dist/timeout-runner.d.ts.map +1 -0
  49. package/dist/types.d.ts +103 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/worker-protocol.d.ts +44 -0
  52. package/dist/worker-protocol.d.ts.map +1 -0
  53. package/dist/yaml-safe.d.ts +34 -0
  54. package/dist/yaml-safe.d.ts.map +1 -0
  55. package/package.json +13 -13
package/dist/index.d.ts CHANGED
@@ -1,502 +1,19 @@
1
1
  /**
2
- * Workbook type definitions
3
- */
4
- /**
5
- * Supported cell types
6
- */
7
- type CellType = 'markdown' | 'code' | 'tensor' | 'equation' | 'visualization' | 'data' | 'test' | 'export';
8
- /**
9
- * Execution modes
10
- */
11
- type ExecutionMode = 'reactive' | 'sequential' | 'manual';
12
- /**
13
- * Workbook metadata
14
- */
15
- interface WorkbookMetadata {
16
- title?: string;
17
- author?: string;
18
- description?: string;
19
- tags?: string[];
20
- created?: string;
21
- modified?: string;
22
- }
23
- /**
24
- * Runtime configuration
25
- */
26
- interface RuntimeConfig {
27
- engine: 'mathts' | 'custom';
28
- execution: ExecutionMode;
29
- timeout?: number;
30
- }
31
- /**
32
- * Individual cell in a workbook
33
- */
34
- interface Cell {
35
- id: string;
36
- type: CellType;
37
- content: string;
38
- dependsOn?: string[];
39
- output?: unknown;
40
- error?: string;
41
- metadata?: Record<string, unknown>;
42
- }
43
- /**
44
- * Complete workbook structure
45
- */
46
- interface Workbook {
47
- version: string;
48
- metadata: WorkbookMetadata;
49
- runtime: RuntimeConfig;
50
- cells: Cell[];
51
- }
52
- /**
53
- * Parse result with validation
54
- */
55
- interface ParseResult {
56
- success: boolean;
57
- workbook?: Workbook;
58
- errors?: string[];
59
- warnings?: string[];
60
- }
61
- /**
62
- * Workbook execution events
63
- */
64
- interface WorkbookEvent {
65
- type: 'cell:start' | 'cell:success' | 'cell:error' | 'cell:stale' | 'workbook:complete';
66
- cellId?: string;
67
- output?: unknown;
68
- error?: string;
69
- timestamp: number;
70
- }
71
- /**
72
- * Result of executing a single cell in a run report.
73
- */
74
- interface CellResult {
75
- id: string;
76
- type: CellType;
77
- status: 'success' | 'error' | 'pass' | 'fail';
78
- output?: unknown;
79
- error?: string;
80
- }
81
- /**
82
- * Aggregated result of running an entire workbook (continue-on-error).
83
- */
84
- interface RunResult {
85
- cells: CellResult[];
86
- ok: boolean;
87
- }
88
- /**
89
- * Dependency graph node
90
- */
91
- interface DependencyNode {
92
- id: string;
93
- dependencies: string[];
94
- dependents: string[];
95
- }
96
- /**
97
- * Dependency graph
98
- */
99
- interface DependencyGraph {
100
- nodes: Map<string, DependencyNode>;
101
- executionOrder: string[];
102
- }
103
-
104
- /**
105
- * Workbook YAML parser
106
- */
107
-
108
- /**
109
- * Detect cell type from YAML keys (first match by precedence).
110
- */
111
- declare function detectCellType(cell: Record<string, unknown>): CellType;
112
- /**
113
- * Parse a workbook from YAML content.
114
- */
115
- declare function parseWorkbook(content: string): ParseResult;
116
- /**
117
- * Serialize a workbook to YAML that round-trips through {@link parseWorkbook}.
118
- *
119
- * Structural fidelity (version/metadata/runtime/cells: id/type/content/dependsOn/
120
- * metadata) is exact. Persisted `output` values are best-effort: plain
121
- * primitives/arrays/objects round-trip exactly (the YAML serializer quotes
122
- * scalars that would otherwise re-type); exotic class instances serialize to
123
- * their plain shape. Throws only on a structurally invalid workbook.
124
- */
125
- declare function serializeWorkbook(workbook: Workbook): string;
126
- /**
127
- * Strip outputs from workbook (for git)
128
- */
129
- declare function stripOutputs(workbook: Workbook): Workbook;
130
-
131
- /**
132
- * Dependency graph management
133
- */
134
-
135
- /**
136
- * Build dependency graph from cells
137
- */
138
- declare function buildDependencyGraph(cells: Cell[]): DependencyGraph;
139
- /**
140
- * Topological sort for execution order
141
- */
142
- declare function topologicalSort(nodes: Map<string, DependencyNode>): string[];
143
- /**
144
- * Get all cells that depend on a given cell
145
- */
146
- declare function getDependents(graph: DependencyGraph, cellId: string): string[];
147
- /**
148
- * All transitive dependencies of `id` plus `id` itself (its ancestor closure).
149
- * Used to run a single cell together with everything it needs. Cycle-safe via
150
- * a visited set; returns `[]` if `id` is not in the graph.
151
- */
152
- declare function getAncestors(graph: DependencyGraph, id: string): string[];
153
- /**
154
- * Render the dependency graph as a Mermaid `graph TD` diagram.
155
- *
156
- * Cell ids are validated identifiers (`[A-Za-z_][A-Za-z0-9_]*`), so they are
157
- * safe to use verbatim as both the node id and its quoted label — Mermaid
158
- * syntax injection is impossible and no cell content appears in the output.
159
- */
160
- declare function toMermaid(graph: DependencyGraph): string;
161
- /**
162
- * Detect circular dependencies
163
- */
164
- declare function detectCycles(graph: DependencyGraph): string[][];
165
-
166
- /**
167
- * Workbook executor
168
- */
169
-
170
- /**
171
- * Event handler type
172
- */
173
- type EventHandler = (event: WorkbookEvent) => void;
174
- /**
175
- * Workbook executor with reactive execution support
176
- */
177
- declare class WorkbookExecutor {
178
- private workbook;
179
- private graph;
180
- private outputs;
181
- private handlers;
182
- constructor(workbook: Workbook);
183
- /**
184
- * Subscribe to execution events
185
- */
186
- on(handler: EventHandler): () => void;
187
- /**
188
- * Emit an event to all handlers
189
- */
190
- private emit;
191
- /**
192
- * Run all cells in order
193
- */
194
- runAll(): Promise<void>;
195
- /**
196
- * Run a specific cell
197
- */
198
- runCell(cellId: string): Promise<unknown>;
199
- /**
200
- * Execute a single cell
201
- */
202
- private executeCell;
203
- /**
204
- * Build the evaluation scope from a cell's DIRECT dependency outputs.
205
- *
206
- * Dependency outputs are injected as named variables keyed by the
207
- * dependency's cell id, so a cell can reference an earlier cell's result by
208
- * that id. Injection is non-transitive: only ids in `cell.dependsOn` are
209
- * injected (a dependency's own dependencies are not). An output of
210
- * `undefined` (cell never ran) is skipped, so the reference fails loudly.
211
- */
212
- private buildScope;
213
- /**
214
- * Execute a code cell by evaluating its content as a MathTS expression.
215
- *
216
- * Evaluation goes through the MathTS expression engine — property and
217
- * method access route through the expression sandbox, so this does not
218
- * have the arbitrary-code-execution exposure of the `Function` constructor.
219
- */
220
- private executeCode;
221
- /**
222
- * Execute a test cell: evaluate its assertion expression in the dependency
223
- * scope. The result must be a boolean — `runReport` classifies `true` as a
224
- * pass and `false` as a fail. A non-boolean result is a usage error (a test
225
- * that doesn't assert), surfaced via throw like any other evaluation error.
226
- */
227
- private executeTest;
228
- /**
229
- * Execute a data cell — parse its content as YAML (a superset of JSON) using
230
- * the same hardened options + prototype-pollution guard as the document
231
- * parser, so both YAML entry points are consistent.
232
- */
233
- private executeData;
234
- /**
235
- * Run every cell in dependency order and return a structured report.
236
- *
237
- * Unlike {@link runAll} (the event-stream API, which throws on the first cell
238
- * error), `runReport` is the headless/report API: it is **continue-on-error**
239
- * (one failing cell does not abort the rest) and never throws on a cell
240
- * failure. A dependency cycle is refused up front. Test cells are classified
241
- * as `pass`/`fail`/`error`; all other cells as `success`/`error`.
242
- */
243
- /**
244
- * Seed the output cache (for incremental session runs): non-stale cells'
245
- * outputs are provided so downstream cells can read them as scope without
246
- * re-execution. Replaces any existing cached outputs.
247
- */
248
- seedOutputs(entries: Map<string, unknown>): void;
249
- runReport(options?: {
250
- only?: string;
251
- runIds?: Set<string>;
252
- }): Promise<RunResult>;
253
- /**
254
- * Get output from a previous cell
255
- */
256
- getOutput(cellId: string): unknown;
257
- }
258
- /**
259
- * Create an executor for a workbook
260
- */
261
- declare function createExecutor(workbook: Workbook): WorkbookExecutor;
262
-
263
- /**
264
- * Human-readable rendering of cell results for terminal output.
265
- *
266
- * `formatResult` is called inside the executor's continue-on-error loop, so it
267
- * MUST NOT throw — circular references, BigInt, and unserializable values all
268
- * fall back to safe markers rather than crashing the run.
269
- */
270
- declare function formatResult(value: unknown): string;
271
-
272
- /**
273
- * Pure, immutable cell-mutation operations on a Workbook.
274
- *
275
- * Every op returns a NEW workbook (the input is never mutated) and enforces the
276
- * runnable-valid invariants — unique + identifier-safe ids, supported cell
277
- * types, existing `depends_on` references, no self-dependency, and no dependency
278
- * cycle. An op that would break an invariant throws; callers must not write the
279
- * file on a throw.
280
- */
281
-
282
- interface CellPosition {
283
- before?: string;
284
- after?: string;
285
- at?: number;
286
- }
287
- interface RemoveResult {
288
- workbook: Workbook;
289
- /** Cells whose `depends_on` was edited to detach the removed cell (force). */
290
- changedCells: string[];
291
- }
292
- declare function addCell(wb: Workbook, spec: {
293
- id: string;
294
- type: CellType;
295
- content?: string;
296
- dependsOn?: string[];
297
- }, position?: CellPosition): Workbook;
298
- declare function editCell(wb: Workbook, id: string, changes: {
299
- content?: string;
300
- type?: CellType;
301
- dependsOn?: string[];
302
- }): Workbook;
303
- declare function removeCell(wb: Workbook, id: string, options?: {
304
- force?: boolean;
305
- }): RemoveResult;
306
- declare function moveCell(wb: Workbook, id: string, position: CellPosition): Workbook;
307
- declare function renameCell(wb: Workbook, oldId: string, newId: string): Workbook;
308
- /** Update workbook-level metadata fields (only the provided ones). */
309
- declare function setMetadata(wb: Workbook, changes: {
310
- title?: string;
311
- author?: string;
312
- description?: string;
313
- tags?: string[];
314
- }): Workbook;
315
-
316
- /**
317
- * Machine-contract constants shared by the CLI and the public API.
318
- *
319
- * `SCHEMA_VERSION` is the version of the `--json` envelope shape. Clients
320
- * negotiate with the rule: ignore unknown fields when `major` matches; refuse
321
- * on a `major` mismatch. Additive fields bump `minor`; breaking changes bump
322
- * `major`.
323
- */
324
- declare const SCHEMA_VERSION: {
325
- readonly major: 1;
326
- readonly minor: 0;
327
- };
328
- declare const VERSION: string;
329
-
330
- /**
331
- * In-memory editing/execution session for a single workbook — the stateful
332
- * core behind `mtsw serve`. Holds the workbook, a per-cell result cache, and a
333
- * stale set so a `run` only re-executes what an edit invalidated.
334
- *
335
- * File I/O is limited to `open`/`save`; everything else is in-memory. Edits are
336
- * not persisted until `save`.
337
- */
338
-
339
- declare class Session {
340
- workbook: Workbook | null;
341
- path: string | null;
342
- dirty: boolean;
343
- private cache;
344
- private stale;
345
- private require;
346
- /** A cell has a usable, up-to-date result (the basis for "not stale"). */
347
- private hasValidResult;
348
- /** Load a workbook file into the session. Refuses to discard unsaved edits. */
349
- open(path: string, options?: {
350
- force?: boolean;
351
- }): void;
352
- /** Replace the workbook and recompute the stale set by diffing old vs new. */
353
- private commit;
354
- addCell(spec: {
355
- id: string;
356
- type: CellType;
357
- content?: string;
358
- dependsOn?: string[];
359
- }, position?: CellPosition): void;
360
- editCell(id: string, changes: {
361
- content?: string;
362
- type?: CellType;
363
- dependsOn?: string[];
364
- }): void;
365
- removeCell(id: string, options?: {
366
- force?: boolean;
367
- }): string[];
368
- moveCell(id: string, position: CellPosition): void;
369
- renameCell(oldId: string, newId: string): void;
370
- setMetadata(changes: {
371
- title?: string;
372
- author?: string;
373
- description?: string;
374
- tags?: string[];
375
- }): void;
376
- /**
377
- * Incremental run: execute only stale cells in the target set (`only` + its
378
- * ancestors, or the whole workbook), reusing cached outputs for the rest.
379
- * Returns the merged report over the target plus the streamed events.
380
- */
381
- run(only?: string): Promise<{
382
- result: RunResult;
383
- events: WorkbookEventLite[];
384
- }>;
385
- /** The set of cells awaiting (re-)execution. */
386
- staleIds(): string[];
387
- /** Serialize the current workbook and write it atomically. */
388
- save(path?: string): string;
389
- }
390
- /** Slimmed event for streaming (avoids leaking timestamps / handler internals). */
391
- interface WorkbookEventLite {
392
- type: string;
393
- cellId?: string;
394
- error?: string;
395
- }
396
-
397
- /**
398
- * Pure JSON-RPC 2.0 router for `mtsw serve`. `handleRequest(session, request)`
399
- * maps a request to a Session call and returns the response plus any streamed
400
- * `cell/event` notifications — no stdio, so the protocol logic is unit-testable.
401
- */
402
-
403
- interface JsonRpcRequest {
404
- jsonrpc?: string;
405
- id?: string | number | null;
406
- method?: string;
407
- params?: Record<string, unknown>;
408
- }
409
- interface JsonRpcResponse {
410
- jsonrpc: '2.0';
411
- id: string | number | null;
412
- result?: unknown;
413
- error?: {
414
- code: number;
415
- message: string;
416
- };
417
- }
418
- interface JsonRpcEvent {
419
- jsonrpc: '2.0';
420
- method: 'cell/event';
421
- params: {
422
- type: string;
423
- cellId?: string;
424
- error?: string;
425
- };
426
- }
427
- interface HandleResult {
428
- response: JsonRpcResponse;
429
- events: JsonRpcEvent[];
430
- shutdown: boolean;
431
- }
432
- declare function handleRequest(session: Session, request: JsonRpcRequest): Promise<HandleResult>;
433
-
434
- /**
435
- * MathML → SVG typesetting. Wraps a MathML fragment in an SVG document so
436
- * rendered workbooks can emit SVG (browsers, rsvg, inkscape) instead of raw
437
- * MathML. The glyph metrics are a conservative estimate — consumers that need
438
- * pixel-perfect layout should typeset with a real engine; this is the
439
- * no-dependency path the CLI/export uses.
440
- */
441
- interface MathSvgOptions {
442
- /** Display (`block`) or inline. Default `block`. */
443
- display?: 'block' | 'inline';
444
- /** Extra padding in CSS pixels. Default 4. */
445
- padding?: number;
446
- }
447
- /**
448
- * Wrap a MathML fragment (or a full `<math>` document) in an SVG with a
449
- * `foreignObject` so the math remains selectable and scalable.
450
- */
451
- declare function mathMLToSVG(mathml: string, options?: MathSvgOptions): string;
452
-
453
- /**
454
- * Shared message/result shapes between `timeout-runner.ts` (the coordinator,
455
- * running on the caller's thread) and `run-worker.ts` (the `worker_threads`
456
- * entry point that actually executes the workbook). Kept in its own module so
457
- * neither side needs to import the other's runtime code — the worker script
458
- * stays a minimal, independently loadable entry point.
459
- *
460
- * Cell outputs are pre-formatted to strings (via `formatResult`) before they
461
- * cross the worker boundary: `postMessage` uses the structured-clone
462
- * algorithm, which cannot faithfully reproduce engine class instances
463
- * (Complex, matrices, BigNumber, …) — it either drops their prototype or
464
- * throws. Formatting to a string in the worker (the same rendering every
465
- * other report consumer already uses) sidesteps that entirely.
466
- */
467
-
468
- /** A `CellResult` with its output pre-formatted to a string (or absent). */
469
- interface SerializedCellResult {
470
- id: string;
471
- type: CellResult['type'];
472
- status: CellResult['status'];
473
- output?: string;
474
- error?: string;
475
- }
476
- /** A `RunResult` whose cells are `SerializedCellResult`s. */
477
- interface SerializedRunResult {
478
- cells: SerializedCellResult[];
479
- ok: boolean;
480
- }
481
-
482
- interface RunWorkbookWithTimeoutOptions {
483
- /** Wall-clock budget in milliseconds. Exceeding it terminates the worker. */
484
- timeoutMs: number;
485
- }
486
- /** Thrown when a workbook run is terminated for exceeding its time budget. */
487
- declare class WorkbookTimeoutError extends Error {
488
- readonly timeoutMs: number;
489
- constructor(timeoutMs: number);
490
- }
491
- /**
492
- * Run a workbook's `.mtsw` source to completion (a continue-on-error report,
493
- * like `runReport()`) inside a worker thread, killing that worker if it
494
- * exceeds `timeoutMs`. The worker is ALWAYS terminated before this promise
495
- * settles — on timeout, on success, and on error — so no handle is left open
496
- * keeping the process alive.
497
- *
498
- * @throws {WorkbookTimeoutError} if the run is terminated for exceeding the budget.
499
- */
500
- declare function runWorkbookWithTimeout(source: string, options: RunWorkbookWithTimeoutOptions): Promise<SerializedRunResult>;
501
-
502
- export { type Cell, type CellPosition, type CellResult, type CellType, type ExecutionMode, type MathSvgOptions, type ParseResult, type RemoveResult, type RunResult, type RunWorkbookWithTimeoutOptions, type RuntimeConfig, SCHEMA_VERSION, type SerializedCellResult, type SerializedRunResult, Session, VERSION, type Workbook, type WorkbookEvent, WorkbookExecutor, type WorkbookMetadata, WorkbookTimeoutError, addCell, buildDependencyGraph, createExecutor, detectCellType, detectCycles, editCell, formatResult, getAncestors, getDependents, handleRequest, mathMLToSVG, moveCell, parseWorkbook, removeCell, renameCell, runWorkbookWithTimeout, serializeWorkbook, setMetadata, stripOutputs, toMermaid, topologicalSort };
2
+ * @danielsimonjr/mathts-workbook - Scientific workbook runtime
3
+ * @packageDocumentation
4
+ */
5
+ export type { Workbook, Cell, CellType, ExecutionMode, WorkbookMetadata, RuntimeConfig, ParseResult, WorkbookEvent, CellResult, RunResult, } from './types';
6
+ export { parseWorkbook, serializeWorkbook, stripOutputs, detectCellType } from './parser';
7
+ export { buildDependencyGraph, topologicalSort, getDependents, detectCycles, getAncestors, toMermaid, } from './graph';
8
+ export { WorkbookExecutor, createExecutor } from './executor';
9
+ export { formatResult } from './formatter';
10
+ export { addCell, editCell, removeCell, moveCell, renameCell, setMetadata } from './edit';
11
+ export type { CellPosition, RemoveResult } from './edit';
12
+ export { SCHEMA_VERSION, VERSION } from './contract';
13
+ export { Session } from './session';
14
+ export { handleRequest } from './rpc';
15
+ export { mathMLToSVG } from './svg-math';
16
+ export type { MathSvgOptions } from './svg-math';
17
+ export { runWorkbookWithTimeout, WorkbookTimeoutError } from './timeout-runner';
18
+ export type { RunWorkbookWithTimeoutOptions, SerializedCellResult, SerializedRunResult, } from './timeout-runner';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1F,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1F,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChF,YAAY,EACV,6BAA6B,EAC7B,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  renameCell,
12
12
  runWorkbookWithTimeout,
13
13
  setMetadata
14
- } from "./chunk-ZVCYWKM5.js";
14
+ } from "./chunk-JM3ZAYJC.js";
15
15
  import {
16
16
  WorkbookExecutor,
17
17
  buildDependencyGraph,
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Engine introspection shared by the CLI (`capabilities`, `functions`) and the
3
+ * serve JSON-RPC router. Imports only constants + the math package, so both the
4
+ * CLI and the RPC layer can use it without an import cycle.
5
+ */
6
+ import { SCHEMA_VERSION } from './contract';
7
+ /**
8
+ * Names a code cell can call/use, from the exported surface of
9
+ * `@danielsimonjr/mathts-functions`. Names only (no signatures); computed once.
10
+ * Best-effort — the exported surface, not the engine's full internal symbol table.
11
+ */
12
+ export declare function listFunctions(): {
13
+ functions: string[];
14
+ constants: string[];
15
+ };
16
+ /** Capabilities payload — version, cell types, command list, feature flags. */
17
+ export declare function capabilitiesInfo(): {
18
+ name: string;
19
+ version: string;
20
+ schemaVersion: typeof SCHEMA_VERSION;
21
+ cellTypes: {
22
+ supported: string[];
23
+ deferred: string[];
24
+ };
25
+ cellSchemas: Record<string, string>;
26
+ commands: string[];
27
+ features: Record<string, boolean>;
28
+ };
29
+ //# sourceMappingURL=introspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAW,cAAc,EAAiB,MAAM,YAAY,CAAC;AAKpE;;;;GAIG;AACH,wBAAgB,aAAa,IAAI;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAU5E;AAcD,+EAA+E;AAC/E,wBAAgB,gBAAgB,IAAI;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,cAAc,CAAC;IACrC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACvD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAuBA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Assemble a generic RenderDoc into a Jupyter notebook (nbformat v4) JSON
3
+ * string — the ipynb analog of html.ts's toHTML / tex.ts's toTeX. Operates on
4
+ * the same plain `RenderDoc`/`RenderCell` model built by the CLI's
5
+ * `buildRenderDoc`, so it shares the exact same cell/result mapping as the
6
+ * other exporters instead of re-deriving it from the `Workbook` type.
7
+ *
8
+ * Cell mapping:
9
+ * - `markdown` -> an nbformat markdown cell (raw content as source).
10
+ * - everything else (`equation`, `code`, `test`, `data`, `chart`) -> an
11
+ * nbformat code cell. A computed result becomes an `execute_result`
12
+ * output; an error becomes an `error` output; a rendered chart becomes a
13
+ * `display_data` output (inline SVG); a `test` cell's pass/fail becomes an
14
+ * `execute_result` of `"true"`/`"false"`. A cell with none of these (e.g.
15
+ * an unevaluated `equation`, or `--no-run`) gets an empty `outputs` array
16
+ * and `execution_count: null`, which is valid nbformat v4.
17
+ *
18
+ * `source` fields follow the nbformat convention: an array of lines, each
19
+ * (except possibly the last) retaining its trailing `\n`.
20
+ */
21
+ import type { RenderDoc } from './html.js';
22
+ /** Render a document structure to a Jupyter notebook (nbformat v4) JSON string. */
23
+ export declare function toIpynb(doc: RenderDoc): string;
24
+ //# sourceMappingURL=ipynb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipynb.d.ts","sourceRoot":"","sources":["../src/ipynb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAoHvD,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAqB9C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Minimal, dependency-free Markdown → HTML for rendered documents. A small
3
+ * subset (headings, paragraphs, bold/italic/code, fenced code, lists, links,
4
+ * hr) — NOT CommonMark-complete. XSS-safe: text is HTML-escaped first, then
5
+ * inline markers are applied to the escaped text, and link hrefs pass a strict
6
+ * protocol allowlist (not a denylist).
7
+ */
8
+ export declare function markdownToHtml(src: string): string;
9
+ /** Escape LaTeX specials in a single pass (an escape's own backslash/braces are never re-scanned). */
10
+ export declare function texEscape(s: string): string;
11
+ /** Minimal Markdown → LaTeX, same subset + safety discipline as markdownToHtml. */
12
+ export declare function markdownToTex(src: string): string;
13
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2EH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DlD;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa3C;AA+BD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA6DjD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Workbook YAML parser
3
+ */
4
+ import type { Workbook, ParseResult, CellType } from './types';
5
+ /**
6
+ * Canonical cell-type keys, in detection-precedence order. Shared between the
7
+ * `detectCellType` helper and the parser's exactly-one-type-key rule.
8
+ */
9
+ declare const CELL_TYPE_KEYS: CellType[];
10
+ /** Whether a string is a valid cell id (a MathTS identifier). */
11
+ export declare function isValidIdentifier(id: string): boolean;
12
+ /** Cell types the runtime can execute today (the rest are reserved/deferred). */
13
+ export declare const SUPPORTED_CELL_TYPES: CellType[];
14
+ /**
15
+ * Detect cell type from YAML keys (first match by precedence).
16
+ */
17
+ declare function detectCellType(cell: Record<string, unknown>): CellType;
18
+ /**
19
+ * Parse a workbook from YAML content.
20
+ */
21
+ export declare function parseWorkbook(content: string): ParseResult;
22
+ /**
23
+ * Serialize a workbook to YAML that round-trips through {@link parseWorkbook}.
24
+ *
25
+ * Structural fidelity (version/metadata/runtime/cells: id/type/content/dependsOn/
26
+ * metadata) is exact. Persisted `output` values are best-effort: plain
27
+ * primitives/arrays/objects round-trip exactly (the YAML serializer quotes
28
+ * scalars that would otherwise re-type); exotic class instances serialize to
29
+ * their plain shape. Throws only on a structurally invalid workbook.
30
+ */
31
+ export declare function serializeWorkbook(workbook: Workbook): string;
32
+ /**
33
+ * Strip outputs from workbook (for git)
34
+ */
35
+ export declare function stripOutputs(workbook: Workbook): Workbook;
36
+ export { detectCellType, CELL_TYPE_KEYS };
37
+ /**
38
+ * Build a validated Workbook from a structured document (JSON or YAML — YAML is
39
+ * a JSON superset, so both parse). Accepts the friendly, `describe`-style shape
40
+ * `{ metadata?, runtime?, version?, cells: [{ id, type, content, dependsOn? }] }`
41
+ * (the inverse of `describe --json`), normalizes each cell to the `.mtsw` shape,
42
+ * then round-trips through serialize + parse so all the usual validation
43
+ * (identifier ids, uniqueness, supported types, existing deps, no cycle,
44
+ * prototype-pollution) is reused. Returns a ParseResult.
45
+ */
46
+ export declare function importWorkbook(input: string): ParseResult;
47
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,QAAQ,EAIT,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,QAAA,MAAM,cAAc,EAAE,QAAQ,EAS7B,CAAC;AAQF,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,EAO1C,CAAC;AAIF;;GAEG;AACH,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAQ/D;AA8FD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAqE1D;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAmB5D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CASzD;AAED,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAE1C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAkEzD"}
package/dist/pdf.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Render a workbook RenderDoc to a PDF file. Reuses plot's latexToPdf primitive:
3
+ * toTeX(standalone) → LaTeX → PDF. Charts render as native vector TikZ (no
4
+ * rasterization). Async; throws PlotRenderError if no LaTeX engine is available.
5
+ */
6
+ import { type RenderOptions } from '@danielsimonjr/mathts-plot/render';
7
+ import type { RenderDoc } from './html.js';
8
+ export interface ToPdfOptions extends RenderOptions {
9
+ parse?: (expr: string) => unknown;
10
+ }
11
+ export declare function toPDF(doc: RenderDoc, outPath: string, options?: ToPdfOptions): Promise<void>;
12
+ //# sourceMappingURL=pdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACnC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhG"}