@pathmx/path 0.5.0

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 (4) hide show
  1. package/LICENSE.md +172 -0
  2. package/README.md +30 -0
  3. package/index.ts +258 -0
  4. package/package.json +32 -0
package/LICENSE.md ADDED
@@ -0,0 +1,172 @@
1
+ # PathMX Proprietary Beta License
2
+
3
+ Version 0.1 — July 21, 2026
4
+
5
+ Copyright © 2026 DUO Interactive, LLC.
6
+ All rights reserved.
7
+
8
+ This license governs the first-party PathMX software distributed in the npm
9
+ package `@pathmx/core`, including its command-line interface, bundled
10
+ library surfaces, runtime and Player components, and accompanying
11
+ documentation (the “Software”). DUO Interactive, LLC is the “Licensor.” This
12
+ license does not cover the private PathMX source-code repository or separately
13
+ identified third-party materials.
14
+
15
+ “Project” means Paths, Sources, responses, data, and other content authored or
16
+ processed with the Software.
17
+
18
+ “Application” means software or a service created by you in which the Software
19
+ supports product-specific functionality but is not itself offered as a
20
+ general-purpose PathMX product.
21
+
22
+ “Redistributable Components” means runtime, Player, or library portions of the
23
+ Software incorporated into a Project, Application, or generated output through
24
+ ordinary use of the Software or ordinary compilation and bundling tools.
25
+
26
+ “Authorized Users” means your employees and individual contractors who use the
27
+ Software on your behalf, and your hosting, continuous-integration, and other
28
+ service providers that possess or run necessary copies solely to provide
29
+ services to you.
30
+
31
+ ## 1. Agreement
32
+
33
+ By installing, accessing, or using the Software, you agree to this license. If
34
+ you use the Software on behalf of an organization, you represent that you have
35
+ authority to accept this license for that organization. If you do not agree,
36
+ do not install or use the Software.
37
+
38
+ ## 2. License grant
39
+
40
+ Subject to this license, the Licensor grants you a non-exclusive, worldwide,
41
+ royalty-free, non-transferable, and non-sublicensable license, perpetual for
42
+ the version of the Software to which it applies unless terminated under
43
+ Section 10, to:
44
+
45
+ - install, execute, and use the Software for personal, educational,
46
+ internal-business, or commercial purposes;
47
+ - use the Software to author, integrate, build, test, serve, play, host, and
48
+ operate Projects and Applications;
49
+ - import, compile, bundle, configure, and integrate the Software through its
50
+ documented library and command-line interfaces;
51
+ - create and distribute independent Projects, Applications, plugins, and
52
+ integrations that use those interfaces without modifying the Software
53
+ itself; and
54
+ - make copies reasonably necessary for local development, testing, continuous
55
+ integration, backup, and hosted production environments.
56
+
57
+ Your Authorized Users may exercise those rights solely on your behalf. You are
58
+ responsible for their compliance with this license.
59
+
60
+ You may reproduce and distribute Redistributable Components only as
61
+ incorporated into your Project, Application, or generated output, and only when
62
+ you preserve applicable license and proprietary notices. You may host and
63
+ commercially provide access to that Project, Application, or output. You may
64
+ not distribute Redistributable Components as a standalone package or as a
65
+ general-purpose substitute for the Software.
66
+
67
+ Each lawful recipient of a Redistributable Component may execute and use that
68
+ component, display its output, and make technically necessary transitory copies
69
+ solely as incorporated into the Project, Application, or output in which they
70
+ received it. This limited recipient permission does not include a right to
71
+ extract, modify, or redistribute the component separately.
72
+
73
+ ## 3. Restrictions
74
+
75
+ Except where applicable law does not allow the restriction, you may not:
76
+
77
+ - modify, adapt, translate, or create derivative works of the Software, except
78
+ for the compilation, bundling, configuration, and integration expressly
79
+ permitted in Section 2;
80
+ - redistribute, sublicense, sell, lease, or otherwise provide the Software to
81
+ another person as a standalone package, product, or service except to an
82
+ Authorized User or as a Redistributable Component under Section 2;
83
+ - resell, rebrand, or provide the Software as a hosted or managed service that
84
+ gives third parties general-purpose access to substantial PathMX authoring,
85
+ building, serving, Player-administration, or library functionality for their
86
+ own unrelated projects;
87
+ - reverse engineer, decompile, disassemble, or otherwise attempt to derive the
88
+ source code of the Software; or
89
+ - remove or alter copyright, license, trademark, or other proprietary notices.
90
+
91
+ For clarity, the managed-service restriction does not prohibit a hosted
92
+ Project or Application in which PathMX supports the licensee's own
93
+ product-specific experience and is not itself the general-purpose product
94
+ offered to customers.
95
+
96
+ ## 4. Your content
97
+
98
+ As between you and the Licensor, you retain ownership of the Paths, Sources,
99
+ responses, data, independent application code, and other content that you
100
+ author or provide while using the Software. You are responsible for that
101
+ content and for having the rights needed to use it.
102
+
103
+ Generated output may contain Redistributable Components or third-party
104
+ materials. Your ownership of your content does not change the ownership or
105
+ license terms of those components and materials.
106
+
107
+ ## 5. Ownership and trademarks
108
+
109
+ The Software is licensed, not sold. The Licensor and its suppliers retain all
110
+ rights in the Software not expressly granted by this license. This license
111
+ does not grant permission to use the PathMX name, logos, or other marks except
112
+ as reasonably necessary to identify the Software accurately.
113
+
114
+ ## 6. Beta status and changes
115
+
116
+ The Software is a proprietary beta release. Its APIs, behavior, file formats,
117
+ and features may change or be removed without notice. The Licensor has no
118
+ obligation to provide support, maintenance, updates, continued availability,
119
+ or backward compatibility. A later version may be offered under different
120
+ license terms, including an open-source license. Different terms for a later
121
+ version do not change the license previously granted for an earlier version.
122
+
123
+ ## 7. Third-party materials
124
+
125
+ The Software and Redistributable Components may include or depend on
126
+ third-party materials governed by their own license terms. Those terms control
127
+ for the applicable third-party materials. You must preserve third-party notices
128
+ when the applicable third-party terms require it.
129
+
130
+ ## 8. Disclaimer of warranties
131
+
132
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED “AS IS” AND
133
+ “AS AVAILABLE,” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS,
134
+ IMPLIED, OR STATUTORY, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
135
+ PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR THAT THE SOFTWARE WILL BE
136
+ SECURE, ERROR-FREE, OR UNINTERRUPTED.
137
+
138
+ ## 9. Limitation of liability
139
+
140
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE LICENSOR AND ITS CONTRIBUTORS,
141
+ SUPPLIERS, AND AFFILIATES WILL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
142
+ SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES, OR FOR LOSS OF DATA,
143
+ PROFITS, REVENUE, GOODWILL, OR BUSINESS OPPORTUNITY, ARISING FROM OR RELATED TO
144
+ THE SOFTWARE OR THIS LICENSE, EVEN IF ADVISED OF THE POSSIBILITY OF THOSE
145
+ DAMAGES.
146
+
147
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, THEIR TOTAL LIABILITY FOR ALL CLAIMS
148
+ ARISING FROM OR RELATED TO THE SOFTWARE OR THIS LICENSE WILL NOT EXCEED THE
149
+ GREATER OF THE AMOUNT YOU PAID FOR THE SOFTWARE DURING THE TWELVE MONTHS BEFORE
150
+ THE EVENT GIVING RISE TO THE CLAIM OR US$100.
151
+
152
+ ## 10. Termination
153
+
154
+ This license terminates if you materially breach it and do not cure the breach
155
+ within thirty days after receiving written notice from the Licensor. On
156
+ termination, you and your Authorized Users must stop using and delete your
157
+ copies of the Software. Sections 4, 5, 8, 9, 10, and 11 survive termination.
158
+ Termination does not withdraw the limited permission already granted by
159
+ Section 2 to lawful recipients of Redistributable Components distributed
160
+ before termination.
161
+
162
+ ## 11. General
163
+
164
+ If a provision of this license is unenforceable, it will be modified only to
165
+ the minimum extent necessary to make it enforceable, and the remaining
166
+ provisions will continue in effect. Failure to enforce a provision is not a
167
+ waiver. You may not assign or transfer this license without the Licensor's
168
+ written consent. The Licensor may assign this license together with ownership
169
+ of the Software to a successor owner. This license binds and benefits the
170
+ permitted successors and assigns of you and the Licensor. This license is the
171
+ entire agreement concerning the Software unless you and the Licensor have
172
+ signed a separate agreement that expressly replaces it.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # `@pathmx/path`
2
+
3
+ > This package is the current proof-of-concept implementation. The replacement
4
+ > authoring and composition contract is being shaped in
5
+ > [Path plugin](../../apps/pathmx-site/paths/work/path.design.md).
6
+
7
+ The Path semantic owner for the Paths product family. `PathPlugin` contributes
8
+ the `path` Source schema; the same package projects viewer-readable Path
9
+ Sources into ordered, nested steps with stable ids and guarded cycles.
10
+
11
+ Use the Plugin directly when composing a product without the full Paths preset:
12
+
13
+ ```ts
14
+ export { default } from "@pathmx/path"
15
+ ```
16
+
17
+ `projectPath()` and `pathStepIds()` expose the Path structure to downstream
18
+ systems. An unlabeled step derives its id from the href, so inserting Blocks
19
+ does not orphan Completion; author `@step.<id>` when identity must survive a
20
+ destination change. `rollupPathCompletion()` maps stable Path leaves onto a separately
21
+ composed `@pathmx/completion` reader. `PathCompletionContributor` declares
22
+ stable leaf `path/<step-id>` manual keys to the canonical Action; aggregate
23
+ branches remain derived from their children:
24
+
25
+ ```ts
26
+ CompletionPlugin({ contributors: [PathCompletionContributor] })
27
+ ```
28
+
29
+ `@pathmx/paths` supplies that composition. Completion is an optional peer;
30
+ installing Path alone does not install or activate it.
package/index.ts ADDED
@@ -0,0 +1,258 @@
1
+ import {
2
+ definePlugin,
3
+ markdownListItemLink,
4
+ type MarkdownList,
5
+ type MarkdownListItem,
6
+ type SourceDescription,
7
+ type View,
8
+ } from "@pathmx/core"
9
+ import type {
10
+ CompletionContributor,
11
+ CompletionReader,
12
+ CompletionStatus,
13
+ } from "@pathmx/completion"
14
+
15
+ /** Own the ordered Path Source meaning shared by Paths product plugins. */
16
+ export const PathPlugin = definePlugin({
17
+ id: "path",
18
+ schema: {
19
+ sources: {
20
+ path: {
21
+ label: "Path",
22
+ description: "An ordered, optionally nested sequence of Sources.",
23
+ icon: "route",
24
+ color: "emerald",
25
+ },
26
+ },
27
+ },
28
+ })
29
+
30
+ export default PathPlugin
31
+
32
+ export type PathStep = Readonly<{
33
+ id: string
34
+ key: string
35
+ pathId: string
36
+ label: string
37
+ href: string
38
+ target?: Readonly<{ type: "source"; id: string }>
39
+ children: readonly PathStep[]
40
+ cycle?: true
41
+ }>
42
+
43
+ export type PathProjection = Readonly<{
44
+ source: SourceDescription["source"]
45
+ steps: readonly PathStep[]
46
+ }>
47
+
48
+ export type PathCompletionNode = Readonly<{
49
+ step: PathStep
50
+ status: CompletionStatus
51
+ complete: number
52
+ total: number
53
+ children: readonly PathCompletionNode[]
54
+ }>
55
+
56
+ type DraftStep = Omit<PathStep, "children"> & { children: DraftStep[] }
57
+ type StepSource = Readonly<{
58
+ id: string
59
+ blocks: readonly Pick<
60
+ SourceDescription["source"]["blocks"][number],
61
+ "lists"
62
+ >[]
63
+ }>
64
+ type StepDescription = Pick<SourceDescription, "relations"> &
65
+ Readonly<{
66
+ source: StepSource
67
+ }>
68
+
69
+ const STEP_LABEL = /^@step(?:\.([A-Za-z][\w-]*))?(?:\s+(.+))?$/
70
+
71
+ function stableHash(value: string) {
72
+ let hash = 0x811c9dc5
73
+ for (let index = 0; index < value.length; index++) {
74
+ hash ^= value.charCodeAt(index)
75
+ hash = Math.imul(hash, 0x01000193)
76
+ }
77
+ return (hash >>> 0).toString(36)
78
+ }
79
+
80
+ function stepIdentity(label: string, href: string) {
81
+ const directive = label.trim().match(STEP_LABEL)
82
+ const explicit = directive?.[1]
83
+ return {
84
+ id: explicit ?? `step-${stableHash(href)}`,
85
+ label: directive?.[2]?.trim() || (directive ? href : label.trim()),
86
+ }
87
+ }
88
+
89
+ function localSteps(description: StepDescription): DraftStep[] {
90
+ const duplicates = new Map<string, number>()
91
+ function steps(lists: readonly MarkdownList[]): DraftStep[] {
92
+ return lists.flatMap((list) =>
93
+ list.type === "unordered" ? list.items.flatMap((item) => step(item)) : [],
94
+ )
95
+ }
96
+ function step(item: MarkdownListItem): DraftStep[] {
97
+ const link = markdownListItemLink(item)
98
+ if (!link) return []
99
+ const identity = stepIdentity(link.label, link.href)
100
+ const duplicate = duplicates.get(identity.id) ?? 0
101
+ duplicates.set(identity.id, duplicate + 1)
102
+ const id = duplicate ? `${identity.id}-${duplicate + 1}` : identity.id
103
+ const relation = description.relations.find(
104
+ (candidate) => candidate.href === link.href,
105
+ )
106
+ return [
107
+ {
108
+ id,
109
+ key: `${description.source.id}#${id}`,
110
+ pathId: description.source.id,
111
+ label: identity.label,
112
+ href: link.href,
113
+ ...(relation?.target ? { target: relation.target } : {}),
114
+ children: steps(item.children),
115
+ },
116
+ ]
117
+ }
118
+ return description.source.blocks.flatMap((block) => steps(block.lists))
119
+ }
120
+
121
+ function targetsPath(step: Pick<PathStep, "href" | "target">) {
122
+ if (step.target) return step.target.id.endsWith(".path")
123
+ const href = step.href.split(/[?#]/, 1)[0]!.replace(/\/+$/, "")
124
+ return href.endsWith(".path") || href.endsWith(".path.md")
125
+ }
126
+
127
+ function isBranchStep(step: Pick<PathStep, "children" | "href" | "target">) {
128
+ return step.children.length > 0 || targetsPath(step)
129
+ }
130
+
131
+ async function expandSteps(
132
+ view: View,
133
+ description: SourceDescription,
134
+ ancestors: ReadonlySet<string>,
135
+ ): Promise<readonly PathStep[]> {
136
+ const nextAncestors = new Set(ancestors).add(description.source.id)
137
+ return Promise.all(
138
+ localSteps(description).map((step) =>
139
+ expandStep(view, step, nextAncestors),
140
+ ),
141
+ )
142
+ }
143
+
144
+ async function expandStep(
145
+ view: View,
146
+ step: DraftStep,
147
+ ancestors: ReadonlySet<string>,
148
+ ): Promise<PathStep> {
149
+ const authored = await Promise.all(
150
+ step.children.map((child) => expandStep(view, child, ancestors)),
151
+ )
152
+ if (!step.target) return Object.freeze({ ...step, children: authored })
153
+ const nested = await view.describeSource(step.target.id)
154
+ if (!nested || nested.source.type !== "path") {
155
+ return Object.freeze({ ...step, children: authored })
156
+ }
157
+ if (ancestors.has(nested.source.id)) {
158
+ return Object.freeze({ ...step, children: authored, cycle: true })
159
+ }
160
+ const referenced = await expandSteps(view, nested, ancestors)
161
+ return Object.freeze({
162
+ ...step,
163
+ children: Object.freeze([...authored, ...referenced]),
164
+ })
165
+ }
166
+
167
+ /** Expand one visible Path into an ordered tree with guarded Path references. */
168
+ export async function projectPath(
169
+ view: View,
170
+ id: string,
171
+ ): Promise<PathProjection | undefined> {
172
+ const description = await view.describeSource(id)
173
+ if (!description || description.source.type !== "path") return
174
+ return Object.freeze({
175
+ source: description.source,
176
+ steps: Object.freeze(await expandSteps(view, description, new Set())),
177
+ })
178
+ }
179
+
180
+ /** Return local stable step ids without resolving or expanding references. */
181
+ export function pathStepIds(description: StepSource) {
182
+ const ids = new Set<string>()
183
+ const collect = (steps: readonly DraftStep[]) => {
184
+ for (const step of steps) {
185
+ ids.add(step.id)
186
+ collect(step.children)
187
+ }
188
+ }
189
+ collect(localSteps({ source: description, relations: [] }))
190
+ return ids
191
+ }
192
+
193
+ function pathLeafStepIds(description: StepSource) {
194
+ const ids: string[] = []
195
+ const collect = (steps: readonly DraftStep[]) => {
196
+ for (const step of steps) {
197
+ if (isBranchStep(step)) collect(step.children)
198
+ else ids.push(step.id)
199
+ }
200
+ }
201
+ collect(localSteps({ source: description, relations: [] }))
202
+ return ids
203
+ }
204
+
205
+ /** Declare stable authored Path steps to the canonical Completion Action. */
206
+ export const PathCompletionContributor: CompletionContributor = (source) =>
207
+ source.type === "path"
208
+ ? pathLeafStepIds(source).map((id) => ({ key: `path/${id}` }))
209
+ : []
210
+
211
+ function aggregateCompletion(
212
+ reader: CompletionReader,
213
+ actorId: string,
214
+ step: PathStep,
215
+ ): PathCompletionNode {
216
+ const children = step.children.map((child) =>
217
+ aggregateCompletion(reader, actorId, child),
218
+ )
219
+ if (isBranchStep(step)) {
220
+ const complete = children.reduce((sum, child) => sum + child.complete, 0)
221
+ const total = children.reduce((sum, child) => sum + child.total, 0)
222
+ return Object.freeze({
223
+ step,
224
+ status:
225
+ total > 0 && complete === total
226
+ ? "complete"
227
+ : complete > 0
228
+ ? "in-progress"
229
+ : "not-started",
230
+ complete,
231
+ total,
232
+ children: Object.freeze(children),
233
+ })
234
+ }
235
+ const complete =
236
+ reader.read(actorId, {
237
+ source: step.pathId,
238
+ key: `path/${step.id}`,
239
+ })?.outcome === "complete"
240
+ return Object.freeze({
241
+ step,
242
+ status: complete ? "complete" : "not-started",
243
+ complete: complete ? 1 : 0,
244
+ total: 1,
245
+ children: Object.freeze([]),
246
+ })
247
+ }
248
+
249
+ /** Roll generic Completion facts through one projected Path tree. */
250
+ export function rollupPathCompletion(
251
+ reader: CompletionReader,
252
+ actorId: string,
253
+ path: PathProjection,
254
+ ): readonly PathCompletionNode[] {
255
+ return Object.freeze(
256
+ path.steps.map((step) => aggregateCompletion(reader, actorId, step)),
257
+ )
258
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@pathmx/path",
3
+ "description": "Ordered learning-path semantics for PathMX applications.",
4
+ "version": "0.5.0",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/pathmx/pathmx-beta.git",
9
+ "directory": "paths/path"
10
+ },
11
+ "homepage": "https://github.com/pathmx/pathmx-beta#readme",
12
+ "bugs": "https://github.com/pathmx/pathmx-beta/issues",
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/",
16
+ "tag": "beta"
17
+ },
18
+ "type": "module",
19
+ "exports": "./index.ts",
20
+ "engines": {
21
+ "bun": ">=1.4.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@pathmx/completion": "^0.5.0",
25
+ "@pathmx/core": "^0.5.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "@pathmx/completion": {
29
+ "optional": true
30
+ }
31
+ }
32
+ }