@ai-markdown/core 3.0.0-beta.1 → 3.0.0-rc.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.
package/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # @ai-markdown/core
2
2
 
3
- Framework-independent orchestration for ai-markdown adapters, published on the **3.0.0-beta.1** train. It supplies pipeline sessions, block planning, cross-chunk contributions, aggregate footnote trees and streaming coordination. React applications install `@ai-markdown/react@beta`; adapter authors can install `@ai-markdown/core@beta` and `@ai-markdown/engine@beta` directly.
3
+ [![@ai-markdown/core rc](https://img.shields.io/npm/v/@ai-markdown/core/rc?label=npm%20rc&color=orange)](https://www.npmjs.com/package/@ai-markdown/core?activeTab=versions)
4
+ [![@ai-markdown/core monthly downloads](https://img.shields.io/npm/dm/@ai-markdown/core?label=downloads%2Fmonth&color=blue)](https://www.npmjs.com/package/@ai-markdown/core)
5
+ [![TypeScript declarations included](https://img.shields.io/badge/TypeScript-included-3178c6?logo=typescript&logoColor=white)](https://github.com/ai-markdown/ai-markdown/tree/main/packages/core)
6
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/ai-markdown/ai-markdown/blob/main/LICENSE)
4
7
 
5
- This package was the private runtime in the legacy v2.14.1 release. It is now a real external dependency of the React adapter, with an explicit public export list. The old `@ai-react-markdown/core` React package maps to `@ai-markdown/react`, not this package. See the [migration guide](../../docs/framework-transition.md). Beta contracts may change before stable 3.0.0; keep the shared packages at the same exact train version.
8
+ Framework-independent orchestration for ai-markdown adapters, on the **3.0.0-rc.1** train alongside the React and Vue adapters. It supplies pipeline sessions, block planning, cross-chunk contributions, aggregate footnote trees and streaming coordination. Applications install `@ai-markdown/react@rc` or `@ai-markdown/vue@rc`; adapter authors can install `@ai-markdown/core@rc` and `@ai-markdown/engine@rc` directly.
9
+
10
+ This package was the private runtime in the legacy v2.14.1 release. It is now a real external dependency of both framework adapters, with an explicit public export list. The old `@ai-react-markdown/core` React package maps to `@ai-markdown/react`, not this package. See the [migration guide](../../docs/framework-transition.md). Beta contracts may change before stable 3.0.0; keep the shared packages at the same exact train version.
6
11
 
7
12
  ## Responsibility and dependency direction
8
13
 
9
14
  ```text
10
- engine ← core ← React adapter ← Mantine integration
11
- ↑___________________|
15
+ @ai-markdown/react-mantine → @ai-markdown/react (peer)
16
+ @ai-markdown/react → @ai-markdown/core + @ai-markdown/engine
17
+ @ai-markdown/vue → @ai-markdown/core + @ai-markdown/engine
18
+ @ai-markdown/core → @ai-markdown/engine
12
19
  ```
13
20
 
14
21
  The adapter may also consume engine primitives directly. Shared core does not duplicate the engine's public barrel or wrap every engine function merely to rename it. It owns reusable orchestration that would otherwise have to be copied into another framework adapter.
@@ -21,13 +28,13 @@ The adapter may also consume engine primitives directly. Shared core does not du
21
28
  | `blockPlanner.ts` | Reuse eligible retained prefix plans while preserving whole-document reference context | One planner per rendered chunk |
22
29
  | `contribution.ts` | Compare source and policy fingerprints, harvest transformed definition bodies, publish changed committed contributions | One publisher per mounted chunk |
23
30
  | `aggregateFootnotes.ts` | Assemble a document's ordered footnotes and occurrence backrefs as HAST | Returned tree belongs to the caller |
24
- | `cloneHastForRender.ts` | Clone node/children/properties containers before render-time mutation | Returned clone belongs to the caller |
31
+ | `cloneHastForRender.ts` | Clone node/children/properties/data and original-URL containers before render-time mutation | Returned clone belongs to the caller |
25
32
  | `smoothCoordinator.ts` | Order chunk reveal, maintain sticky completion, defer cleanup and coalesce notifications | One coordinator per logical document |
26
33
  | `tailSignal.ts` | Classify a source tail that renders inside a footnote or as an invisible link definition | Pure function over MDAST |
27
34
 
28
35
  The engine remains responsible for grammar, preprocessing, plugin chains, scanners, incremental parsing algorithms, registry storage/indexing, reference resolution and URL policy primitives. Shared core uses those algorithms to implement reusable rendering decisions.
29
36
 
30
- React retains component construction, `ReactNode` caching, contexts, effects, `useSyncExternalStore`, registration lifetimes, provenance credential allocation, final element conversion and DOM cursor measurement. Shared core's root has no React, Vue, Svelte or DOM dependency. Its production source is typechecked without the DOM libraries. Node types supply declarations for cross-host primitives such as `queueMicrotask`; they do not add a Node runtime dependency.
37
+ Framework adapters retain component construction and lifecycle integration. React retains `ReactNode` caching, contexts, effects, `useSyncExternalStore`, registration lifetimes, provenance credential allocation, final element conversion and DOM cursor measurement. Shared core's root has no React, Vue, Svelte or DOM dependency. Its production source is typechecked without the DOM libraries. Node types supply declarations for cross-host primitives such as `queueMicrotask`; they do not add a Node runtime dependency.
31
38
 
32
39
  ## A pipeline session is local to one consumer
33
40
 
@@ -66,7 +73,7 @@ const blocks = planBlocks(trees.mdast, trees.hast, content);
66
73
  // Convert blocks.plan using the host renderer; use item.key for sibling identity.
67
74
  ```
68
75
 
69
- This is an standalone example using the public package entries. A coordinated adapter must obtain a per-instance provenance credential, pass the same credential to the engine's verifier and coordinated handlers, derive actual phantom targets, and preserve definition bodies while registered. A constant credential from an example is not suitable for that path.
76
+ This is a standalone example using the public package entries. A coordinated adapter must obtain a per-instance provenance credential, pass the same credential to the engine's verifier and coordinated handlers, derive actual phantom targets, and preserve definition bodies while registered. A constant credential from an example is not suitable for that path.
70
77
 
71
78
  The host chooses `incrementalParse: false` for a one-shot server render. Shared core does not inspect `window` to infer the host. A later incremental frame starts from fresh state after a non-incremental frame. Call `reset()` when the host invalidates retained parse state because render policy changed. Parse-input identities are also checked by the engine's dependency key; phantom suffix changes remain always-tail input rather than invalidating all retained source.
72
79
 
@@ -74,7 +81,7 @@ An incremental failure clears the retained state before retrying the full pipeli
74
81
 
75
82
  ## Shared preparation decisions
76
83
 
77
- `coordinationPreparation.ts` contains the rules used by both the React adapter and the [private Vue lifecycle prototype](../../prototypes/vue/README.md):
84
+ `coordinationPreparation.ts` contains the rules used by both the React adapter and the [Vue adapter](../vue/README.md):
78
85
 
79
86
  - `derivePhantomTargets({ content, ownLabels, labels }, previous?)` excludes locally owned definitions, then matches normalized source against external labels. Footnote and link namespaces remain separate. If no candidate exists, it skips source normalization; if the result sets match `previous`, it returns that same object. The matching remains the legacy substring over-approximation, not a new Markdown reference parser.
80
87
  - `deriveCoordinationPolicy({ coordinated, registered, preserveOrphanReferences }, previous?)` selects all coordinated handlers, only the orphan-footnote handler, or normal standalone behavior. Registration enables body harvesting even when visible orphan rendering is disabled. A harvesting-only change preserves handler identity. The host resolves any wrapper override before calling this function.
@@ -82,7 +89,7 @@ An incremental failure clears the retained state before retrying the full pipeli
82
89
 
83
90
  These functions do not register, subscribe, publish or mutate their supplied snapshots. Treat label sets and returned objects as immutable; pass a previous result only from the same logical consumer. React retains the previous snapshots in refs and uses memoization; Vue uses local variables behind computed values. The engine and planner still own correctness when a source is replaced or a retained render is discarded.
84
91
 
85
- The Vue prototype validates these decisions with real component lifecycle and SSR execution, while keeping AST/registry objects out of deep reactive proxies. It is not a production Vue renderer and does not yet validate DOM hydration, slots, styling or cursor behavior.
92
+ The published [Vue adapter](../vue/README.md) uses these decisions in its component lifecycle while keeping AST/registry objects out of deep reactive proxies. It has SSR, hydration, slots, base styles and cursor support, with separate adapter and Chromium lifecycle tests. The earlier private prototype is archived under `prototypes/` and is not the application entry point.
86
93
 
87
94
  ## Preparation and commit have different effects
88
95
 
@@ -92,7 +99,7 @@ In React, `useRegistryContribution` owns one session and invokes `commit` from a
92
99
 
93
100
  The contribution fingerprint covers ordered refs, definition source, raw link destinations, owned label sets, phantom target sets and the identity tuple of parse policy. Equal source with changed plugins is not an equal contribution. Equal source with a resolved phantom inside a definition body is not an equal contribution either. Only a changed fingerprint/policy triggers the more expensive body harvest from post-pipeline HAST.
94
101
 
95
- The publisher does not sanitize link URLs at contribution time: each consuming element applies its own final URL policy. Harvested footnote bodies retain plugin output. `buildAggregateTree` clones structural containers before appending backrefs, so assembly does not mutate registry-owned bodies. The clone intentionally shares `position`, `data` and individual property values; it is not an unrestricted deep clone for arbitrary consumer mutation.
102
+ The publisher does not sanitize link URLs at contribution time: each consuming element applies its own final URL policy. Harvested footnote bodies retain plugin output. `buildAggregateTree` clones structural containers before appending backrefs, so assembly does not mutate registry-owned bodies. The clone copies `data` and its `originalUrls` container while sharing `position`, other nested plugin data and individual property values; it is not an unrestricted deep clone for arbitrary consumer mutation.
96
103
 
97
104
  Cleanup is also the host's responsibility. Release its registry registration and smooth coordinator slot when the chunk unmounts. The coordinator defers removal to a microtask so an immediate cleanup/re-register pair can revive the same slot without reordering it. Completion is sticky while registered; progress heartbeats do not notify every subscriber on each reveal frame.
98
105
 
@@ -110,15 +117,18 @@ The retained-prefix planner reuses only identity-proven eligible nodes. It retai
110
117
  pnpm install --frozen-lockfile
111
118
  pnpm build
112
119
  pnpm --filter @ai-markdown/core typecheck
113
- pnpm exec vitest run --project unit packages/core/src/runtime.test.ts
120
+ pnpm --filter @ai-markdown/core test
121
+ pnpm test:core-contracts
114
122
  pnpm preflight
115
123
  ```
116
124
 
117
125
  Build before running distribution tests: they load the actual ESM/CJS production and development files in separate Node processes, reject UI framework resolution transitively and parse without browser globals. Other tests compare session output with an independent full engine pipeline, exercise resets/fallback, prove explicit contribution timing and check aggregate body immutability. Existing React tests still exercise the adapter's delegation, memoization, byte equivalence, coordination and browser behavior.
118
126
 
127
+ The dedicated `test:core-contracts` gate builds core and its workspace dependencies, typechecks it, and runs all core tests independently of React/Vue. It runs in preflight, a dedicated CI task and the release workflow. Pure planner, coordinator, tail-signal and block-plan tests live with core; React retains renderer/cache integration tests. Fixed-seed sequences compare retained pipeline/planning and contribution state against full reconstruction, and coordinator lifecycles against a separate model. See [core testing](../../docs/core-testing.md) for the module map, fixed budgets, replay commands and limitations.
128
+
119
129
  `assert-boundary.mjs` checks public-package identity, allowed production dependencies, source import direction and folded environment gates. The React distribution guard requires external core and engine imports. Core's declarations must not expose `RegistryInternal`, `SmoothCoordinatorInternal` or private refcount/subscriber containers.
120
130
 
121
- The release train is engine/core/react/react-mantine at the same version. Core depends on engine through `workspace:*`, which becomes the exact train version in the published manifest. Both ESM and CJS have production and development entries; every build folds environment gates separately. Core has no `use client` directive and does not inline a second engine implementation.
131
+ The release train is engine/core/react/react-mantine/vue at the same version. Vue now consumes the same shared contracts; see the [API contracts](../../docs/api/core-engine-contracts.md) for the beta.1-to-beta.2 signature changes. Core depends on engine through `workspace:*`, which becomes the exact train version in the published manifest. Both ESM and CJS have production and development entries; every build folds environment gates separately. Core has no `use client` directive and does not inline a second engine implementation.
122
132
 
123
133
  ## Public API and write capabilities
124
134
 
@@ -126,4 +136,4 @@ The root entry explicitly lists supported beta exports. Session creation, parsin
126
136
 
127
137
  `createSmoothCoordinator` returns the read-only state and documented methods of `SmoothCoordinator`, excluding internal refcounts and notification containers. `ContributionOptions.registry` accepts only a `ContributionRegistry` write capability with `contributeChunkData`; it does not require an implementation registry. Create a registry through engine's `createRegistry`, whose `RegistryController` adds registration and publication to the read-only `Registry` contract. Pair every registration with release in the owning adapter.
128
138
 
129
- These are type-level API boundaries, not object freezing or arbitrary deep cloning. Mutating returned sets, tree data or undocumented implementation fields is unsupported. A beta upgrade can refine the contract; stable 3.0.0 will require another signature review and consumer validation.
139
+ These are type-level API boundaries, not object freezing or arbitrary deep cloning. Mutating returned sets, tree data or undocumented implementation fields is unsupported. A beta upgrade can refine the contract; the contracts and checked signatures are recorded in the [API contract document](../../docs/api/core-engine-contracts.md). Stable 3.0.0 still requires release approval and current-candidate validation.
package/dist/index.cjs CHANGED
@@ -633,6 +633,11 @@ function cloneHastForRender(node) {
633
633
  if (withProperties.properties) {
634
634
  withProperties.properties = { ...withProperties.properties };
635
635
  }
636
+ if (copy.data) {
637
+ copy.data = { ...copy.data };
638
+ const data = copy.data;
639
+ if (data.originalUrls) data.originalUrls = { ...data.originalUrls };
640
+ }
636
641
  return copy;
637
642
  }
638
643