@pathmx/completion 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.
- package/LICENSE.md +172 -0
- package/README.md +171 -0
- package/contributors.ts +145 -0
- package/evidence.ts +46 -0
- package/index.ts +251 -0
- package/model.ts +50 -0
- package/package.json +39 -0
- package/react.tsx +116 -0
- package/state.ts +220 -0
- package/targets.ts +240 -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,171 @@
|
|
|
1
|
+
# `@pathmx/completion`
|
|
2
|
+
|
|
3
|
+
The opt-in, domain-neutral Completion primitive for PathMX. It owns stable
|
|
4
|
+
Source-local leaf references, Actor-owned outcomes, flat summaries, State
|
|
5
|
+
persistence, authored manual targets, and the canonical set/unset Action. It
|
|
6
|
+
does not own Path trees, forms, or domain rollups.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createCompletionPlugin } from "@pathmx/completion"
|
|
10
|
+
|
|
11
|
+
const completion = createCompletionPlugin()
|
|
12
|
+
|
|
13
|
+
export const plugins = [completion.plugin]
|
|
14
|
+
|
|
15
|
+
completion.reader.read(actor.id, {
|
|
16
|
+
source: "/lessons/setup.page",
|
|
17
|
+
key: "task/install",
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Authored targets
|
|
22
|
+
|
|
23
|
+
A Source or authored Block can declare a manual target with the owned
|
|
24
|
+
`completion` schema prop. Source targets use `source/self`; Block targets use
|
|
25
|
+
their required stable authored id:
|
|
26
|
+
|
|
27
|
+
```md
|
|
28
|
+
---
|
|
29
|
+
completion:
|
|
30
|
+
target: true
|
|
31
|
+
label: Finish this lesson
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
# Lesson
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
<!--
|
|
39
|
+
id: practice
|
|
40
|
+
completion:
|
|
41
|
+
target: true
|
|
42
|
+
label: Finish the practice
|
|
43
|
+
optional: true
|
|
44
|
+
-->
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A trailing task mark produces a stable `task/<id>` target without obscuring
|
|
48
|
+
the human label:
|
|
49
|
+
|
|
50
|
+
```md
|
|
51
|
+
- [ ] Install dependencies {#install}
|
|
52
|
+
- [ ] Explore the bonus {#bonus .optional}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`completionTargets(source)` projects the same frozen target model from a
|
|
56
|
+
canonical `Source` or viewer-safe `SourceView`. The Completion Action is
|
|
57
|
+
available only when the current Source has valid configured targets; it binds
|
|
58
|
+
the Source id and validates the submitted key and optionality.
|
|
59
|
+
|
|
60
|
+
Domains using Completion-owned manual facts can contribute only their stable
|
|
61
|
+
keys and optionality:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const completion = createCompletionPlugin({
|
|
65
|
+
contributors: [
|
|
66
|
+
(source) =>
|
|
67
|
+
source.type === "project"
|
|
68
|
+
? [{ key: "project/launch", optional: false }]
|
|
69
|
+
: [],
|
|
70
|
+
],
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The domain continues to own labels, structure, and rollups. Derived evidence
|
|
75
|
+
such as a valid Input submission remains owned by its provider and uses a
|
|
76
|
+
separate read contract rather than writing a duplicate manual fact:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createCompletionPlugin } from "@pathmx/completion"
|
|
80
|
+
import { createInputPlugin } from "@pathmx/core/plugins"
|
|
81
|
+
|
|
82
|
+
const input = createInputPlugin()
|
|
83
|
+
const completion = createCompletionPlugin({
|
|
84
|
+
evidence: [input.completion],
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export const plugins = [input.plugin, completion.plugin]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Input completion is declared on one stable authored Block, making the form or
|
|
91
|
+
question container—not each field—the semantic leaf:
|
|
92
|
+
|
|
93
|
+
```md
|
|
94
|
+
<!--
|
|
95
|
+
id: reflection
|
|
96
|
+
input-response:
|
|
97
|
+
completion: true
|
|
98
|
+
-->
|
|
99
|
+
|
|
100
|
+
<x-input-text name="response" label="Reflection" required />
|
|
101
|
+
<x-input-submit label="Save response" />
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This declares `input/reflection`. It becomes complete only when that Actor has
|
|
105
|
+
a submitted Input State whose values still validate against the current
|
|
106
|
+
authored fields. The derived target never exposes `completion:set` and never
|
|
107
|
+
writes Completion State. Input currently owns one aggregate State per Source,
|
|
108
|
+
so a Source may declare one Input completion Block.
|
|
109
|
+
|
|
110
|
+
`pmx lint` reports malformed props, unstable Block targets, checked or empty
|
|
111
|
+
marked tasks, invalid and duplicate keys, stale facts, manual/derived
|
|
112
|
+
collisions, and invalid skips for the currently configured contributors and
|
|
113
|
+
evidence providers. Input additionally reports invalid completion containers,
|
|
114
|
+
bound State references, and stored values.
|
|
115
|
+
|
|
116
|
+
State is grouped by originating Source and stores only terminal leaf outcomes:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
---
|
|
120
|
+
type: state
|
|
121
|
+
plugin: completion
|
|
122
|
+
for: /lessons/setup.page
|
|
123
|
+
items:
|
|
124
|
+
task/install:
|
|
125
|
+
outcome: complete
|
|
126
|
+
occurred_at: 2026-08-22T12:00:00.000Z
|
|
127
|
+
task/bonus:
|
|
128
|
+
outcome: skipped
|
|
129
|
+
occurred_at: 2026-08-22T12:05:00.000Z
|
|
130
|
+
---
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`occurred_at` is the occurrence time of the current terminal fact. Repeating
|
|
134
|
+
the same outcome preserves it; clearing and completing again records a new
|
|
135
|
+
time. `pending` is represented by the absence of an item. Provider evidence is
|
|
136
|
+
read through the composed Completion reader; domain rollups remain with their
|
|
137
|
+
owning plugins.
|
|
138
|
+
|
|
139
|
+
## React apps
|
|
140
|
+
|
|
141
|
+
React remains an optional subpath:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import {
|
|
145
|
+
CompletionProvider,
|
|
146
|
+
useCompletion,
|
|
147
|
+
useCompletionAction,
|
|
148
|
+
} from "@pathmx/completion/react"
|
|
149
|
+
|
|
150
|
+
function Task() {
|
|
151
|
+
const fact = useCompletion("task/install")
|
|
152
|
+
const completion = useCompletionAction("task/install")
|
|
153
|
+
return (
|
|
154
|
+
<button
|
|
155
|
+
disabled={completion.pending}
|
|
156
|
+
onClick={() => completion.set(fact ? "pending" : "complete")}
|
|
157
|
+
>
|
|
158
|
+
{fact ? "Completed" : "Mark complete"}
|
|
159
|
+
</button>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
;<CompletionProvider initial={serverProjectedFacts}>
|
|
164
|
+
<Task />
|
|
165
|
+
</CompletionProvider>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The App Component server renderer supplies `serverProjectedFacts` for the
|
|
169
|
+
current viewer. The browser receives no Completion reader or repository
|
|
170
|
+
access. See `labs/assessment/plugins/class-assessment` for a complete App
|
|
171
|
+
Component using the same provider with derived submission completion.
|
package/contributors.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Source } from "@pathmx/core"
|
|
2
|
+
import {
|
|
3
|
+
COMPLETION_KEY,
|
|
4
|
+
type CompletionFact,
|
|
5
|
+
type CompletionRef,
|
|
6
|
+
} from "./model.ts"
|
|
7
|
+
import { completionTargets, type CompletionTarget } from "./targets.ts"
|
|
8
|
+
|
|
9
|
+
export type CompletionContributor = (
|
|
10
|
+
source: Source,
|
|
11
|
+
) => readonly Readonly<{ key: string; optional?: boolean }>[]
|
|
12
|
+
|
|
13
|
+
export type CompletionEvidence = Readonly<{
|
|
14
|
+
declarations: CompletionContributor
|
|
15
|
+
read(
|
|
16
|
+
actorId: string,
|
|
17
|
+
ref: CompletionRef,
|
|
18
|
+
): Readonly<{ fact?: CompletionFact }> | undefined
|
|
19
|
+
}>
|
|
20
|
+
|
|
21
|
+
type CompletionDeclaration = Readonly<{
|
|
22
|
+
key: string
|
|
23
|
+
optional: boolean
|
|
24
|
+
}>
|
|
25
|
+
|
|
26
|
+
function declaration(
|
|
27
|
+
source: Source,
|
|
28
|
+
value: Readonly<{ key: string; optional?: boolean }>,
|
|
29
|
+
): { declaration?: CompletionDeclaration; issue?: string } {
|
|
30
|
+
if (
|
|
31
|
+
typeof value.key !== "string" ||
|
|
32
|
+
value.key.length > 256 ||
|
|
33
|
+
!COMPLETION_KEY.test(value.key)
|
|
34
|
+
) {
|
|
35
|
+
return {
|
|
36
|
+
issue: `Invalid contributed Completion key ${String(value.key)} on ${source.id}.`,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (value.optional !== undefined && typeof value.optional !== "boolean") {
|
|
40
|
+
return {
|
|
41
|
+
issue: `Completion target ${value.key} on ${source.id} has invalid optional data.`,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
declaration: Object.freeze({
|
|
46
|
+
key: value.key,
|
|
47
|
+
optional: value.optional === true,
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function inspectDeclarations(
|
|
53
|
+
source: Source,
|
|
54
|
+
values: readonly Readonly<{ key: string; optional?: boolean }>[],
|
|
55
|
+
duplicateLabel: string,
|
|
56
|
+
) {
|
|
57
|
+
const inspected = values.map((value) => declaration(source, value))
|
|
58
|
+
const issues = inspected.flatMap(({ issue }) => (issue ? [issue] : []))
|
|
59
|
+
const valid = inspected.flatMap(({ declaration }) =>
|
|
60
|
+
declaration ? [declaration] : [],
|
|
61
|
+
)
|
|
62
|
+
const counts = new Map<string, number>()
|
|
63
|
+
for (const target of valid) {
|
|
64
|
+
counts.set(target.key, (counts.get(target.key) ?? 0) + 1)
|
|
65
|
+
}
|
|
66
|
+
for (const [key, count] of counts) {
|
|
67
|
+
if (count > 1) {
|
|
68
|
+
issues.push(
|
|
69
|
+
`Duplicate ${duplicateLabel} Completion target ${key} on ${source.id}.`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
declarations: Object.freeze(
|
|
75
|
+
valid.filter((target) => counts.get(target.key) === 1),
|
|
76
|
+
),
|
|
77
|
+
valid: Object.freeze(valid),
|
|
78
|
+
issues: Object.freeze(issues),
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function inspectCompletionDeclarations(
|
|
83
|
+
source: Source,
|
|
84
|
+
contributors: readonly CompletionContributor[],
|
|
85
|
+
contentTargets: readonly CompletionTarget[] = completionTargets(source),
|
|
86
|
+
) {
|
|
87
|
+
return inspectDeclarations(
|
|
88
|
+
source,
|
|
89
|
+
[
|
|
90
|
+
...contentTargets.map(({ ref, optional }) => ({
|
|
91
|
+
key: ref.key,
|
|
92
|
+
optional,
|
|
93
|
+
})),
|
|
94
|
+
...contributors.flatMap((contribute) => contribute(source)),
|
|
95
|
+
],
|
|
96
|
+
"contributed",
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function inspectConfiguredCompletionDeclarations(
|
|
101
|
+
source: Source,
|
|
102
|
+
contributors: readonly CompletionContributor[],
|
|
103
|
+
evidence: readonly CompletionEvidence[],
|
|
104
|
+
contentTargets: readonly CompletionTarget[] = completionTargets(source),
|
|
105
|
+
) {
|
|
106
|
+
const manual = inspectCompletionDeclarations(
|
|
107
|
+
source,
|
|
108
|
+
contributors,
|
|
109
|
+
contentTargets,
|
|
110
|
+
)
|
|
111
|
+
const derived = inspectDeclarations(
|
|
112
|
+
source,
|
|
113
|
+
evidence.flatMap((provider) => provider.declarations(source)),
|
|
114
|
+
"derived",
|
|
115
|
+
)
|
|
116
|
+
const manualKeys = new Set(manual.valid.map(({ key }) => key))
|
|
117
|
+
const derivedKeys = new Set(derived.valid.map(({ key }) => key))
|
|
118
|
+
const collisions = [...manualKeys].filter((key) => derivedKeys.has(key))
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
manual: Object.freeze(
|
|
121
|
+
manual.declarations.filter(({ key }) => !derivedKeys.has(key)),
|
|
122
|
+
),
|
|
123
|
+
derived: Object.freeze(
|
|
124
|
+
derived.declarations.filter(({ key }) => !manualKeys.has(key)),
|
|
125
|
+
),
|
|
126
|
+
issues: Object.freeze([
|
|
127
|
+
...manual.issues,
|
|
128
|
+
...derived.issues,
|
|
129
|
+
...collisions.map(
|
|
130
|
+
(key) =>
|
|
131
|
+
`Completion target ${key} on ${source.id} is both manual and derived.`,
|
|
132
|
+
),
|
|
133
|
+
]),
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Combine built-in content declarations with configured domain contributors. */
|
|
138
|
+
export function completionDeclarations(
|
|
139
|
+
source: Source,
|
|
140
|
+
contributors: readonly CompletionContributor[],
|
|
141
|
+
evidence: readonly CompletionEvidence[] = [],
|
|
142
|
+
) {
|
|
143
|
+
return inspectConfiguredCompletionDeclarations(source, contributors, evidence)
|
|
144
|
+
.manual
|
|
145
|
+
}
|
package/evidence.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CompletionEvidence } from "./contributors.ts"
|
|
2
|
+
import {
|
|
3
|
+
completionSummary,
|
|
4
|
+
type CompletionFact,
|
|
5
|
+
type CompletionReader,
|
|
6
|
+
type CompletionRef,
|
|
7
|
+
} from "./model.ts"
|
|
8
|
+
|
|
9
|
+
const AMBIGUOUS_EVIDENCE: Readonly<{ fact?: CompletionFact }> = Object.freeze(
|
|
10
|
+
{},
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
function derivedEvidence(
|
|
14
|
+
evidence: readonly CompletionEvidence[],
|
|
15
|
+
actorId: string,
|
|
16
|
+
ref: CompletionRef,
|
|
17
|
+
) {
|
|
18
|
+
let owned: Readonly<{ fact?: CompletionFact }> | undefined
|
|
19
|
+
for (const provider of evidence) {
|
|
20
|
+
const result = provider.read(actorId, ref)
|
|
21
|
+
if (!result) continue
|
|
22
|
+
if (owned) return AMBIGUOUS_EVIDENCE
|
|
23
|
+
owned = result
|
|
24
|
+
}
|
|
25
|
+
return owned
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Overlay provider-owned evidence without copying it into Completion State. */
|
|
29
|
+
export function completionReader(
|
|
30
|
+
manual: CompletionReader,
|
|
31
|
+
evidence: readonly CompletionEvidence[],
|
|
32
|
+
): CompletionReader {
|
|
33
|
+
const read = (
|
|
34
|
+
actorId: string,
|
|
35
|
+
ref: CompletionRef,
|
|
36
|
+
): CompletionFact | undefined => {
|
|
37
|
+
const derived = derivedEvidence(evidence, actorId, ref)
|
|
38
|
+
return derived ? derived.fact : manual.read(actorId, ref)
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
read,
|
|
42
|
+
summary(actorId, refs) {
|
|
43
|
+
return completionSummary(refs, (ref) => read(actorId, ref))
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
}
|