@bespokeagentics/microdots-host 0.1.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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@bespokeagentics/microdots-host",
3
+ "version": "0.1.0",
4
+ "description": "MicroDots host shell — registry, loader, slot manifest and placement checks for mounting MicroDot custom elements. Raw TypeScript source; consume with Bun or Vite.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/qdhenry/BespokeAgenticsEffectfulMicroApps.git",
10
+ "directory": "packages/microdots-host"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./src/index.ts",
16
+ "exports": {
17
+ ".": "./src/index.ts"
18
+ },
19
+ "dependencies": {
20
+ "@bespokeagentics/microdots-element": "0.1.0"
21
+ },
22
+ "peerDependencies": {
23
+ "effect": "4.0.0-rc.108"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * `@bespokeagentics/microdots-host` — the half of a host that is not specific to any host.
3
+ *
4
+ * A host is a **role**, not an app: any page that mounts MicroDots. Three of
5
+ * them exist in this repo (`apps/host`, `apps/cross-origin-demo`,
6
+ * `apps/embedding-demo`) and the interesting one is a page outside it
7
+ * altogether. What they share is here; what makes each of them a particular
8
+ * demo — its registry rows, its route table, its markup — stays with the app.
9
+ *
10
+ * Extracted 2026-08-17 by
11
+ * `wiki/plans/shipped/microdots-framework-and-platform-separation.md`
12
+ * Phase D1. Before that, every function here closed over the demo host's own
13
+ * module-level data, which is why `apps/cross-origin-demo` had grown a
14
+ * registry-free re-implementation rather than importing one.
15
+ *
16
+ * Relative imports in this package carry explicit `.ts` extensions: since
17
+ * Phase 4 the workbench export pipeline value-imports this package, which puts
18
+ * it on a vite CONFIG's import chain — esbuild externalizes the bare
19
+ * specifier, so plain node loads these files via type-stripping, and node
20
+ * resolves relative TS imports only with the extension spelled out.
21
+ */
22
+ export {
23
+ type MicroDotEntry,
24
+ type MicroDotRegistry,
25
+ apiUrlFor,
26
+ findEntry,
27
+ } from './registry.ts'
28
+
29
+ export {
30
+ type Placement,
31
+ type RouteDefinition,
32
+ type RouteTable,
33
+ allSectionIds,
34
+ findPlacement,
35
+ findRoute,
36
+ hrefFor,
37
+ makeRouteTable,
38
+ parseRoutePath,
39
+ routeForHash,
40
+ unroutedTags,
41
+ } from './routes.ts'
42
+
43
+ export {
44
+ createMicroDot,
45
+ createMicroDotFromEntry,
46
+ loadMicroDot,
47
+ mountMicroDot,
48
+ setMicroDotAttribute,
49
+ } from './loader.ts'
50
+
51
+ /**
52
+ * The wire record and its derivations — Phase 4 of
53
+ * `wiki/plans/active/microdots-platform-phase-programme.md`.
54
+ * The schema consts (`Wire`, `HostTopology`, …) carry their decoded Types
55
+ * under the same names. `PlacementCondition`, `PlacementSpan` and `RouteRule`
56
+ * are the Phase-5 widening — work items 2 and 3 of
57
+ * `wiki/plans/shipped/microdots-platform-phase-5-pages-design.md`.
58
+ */
59
+ export {
60
+ type WireState,
61
+ deriveWireState,
62
+ HostTopology,
63
+ PlacementCondition,
64
+ PlacementSpan,
65
+ RouteRule,
66
+ TopologyHost,
67
+ TopologyOverview,
68
+ TopologyPlacement,
69
+ TopologyRoute,
70
+ topologyRouteTable,
71
+ Wire,
72
+ WireEnv,
73
+ WireTransform,
74
+ WireValueType,
75
+ } from './wire.ts'
76
+
77
+ /**
78
+ * The host slot manifest — Phase 5 work item 1: a host declaring, as data and
79
+ * versioned by theme, where MicroDots may go. Lives inside
80
+ * `host-topology.json` as `HostTopology.slotManifest`.
81
+ */
82
+ export { HostSlotManifest, SlotKind, SlotSpec } from './slots.ts'
83
+
84
+ /**
85
+ * Rules, THE matcher, and the reading-B resolution — Phase 5 work item 3.
86
+ * `ruleMatches` is the one matcher (ruling 1): the runtime resolution and the
87
+ * Pages screen's match counts both call it, and nothing else may reimplement
88
+ * it. `resolvePlacements` is the reading-B override resolution.
89
+ */
90
+ export {
91
+ type PlacementOverride,
92
+ type PlacementSource,
93
+ type ResolvedCondition,
94
+ type ResolvedPlacement,
95
+ type ResolvedState,
96
+ conditionIntersection,
97
+ conditionLabel,
98
+ conditionsOverlap,
99
+ resolveCondition,
100
+ resolvePlacements,
101
+ ruleMatches,
102
+ } from './rules.ts'
103
+
104
+ /**
105
+ * The two steps between the resolution and the DOM, shared because both shells
106
+ * need both and apps must not import each other: `pendingMounts` (dedupe by
107
+ * tag as the pending list is built, never after) and `mountOverridesFor`
108
+ * (resume overrides dropped when empty BEFORE the merge).
109
+ */
110
+ export { mountOverridesFor, pendingMounts } from './mounting.ts'
111
+
112
+ /**
113
+ * The placement checks engine — Phase 5 work item 4: six of the spec's seven
114
+ * checks as a pure lint over the resolution's output (check 5 defers with
115
+ * anchors). Unverifiable checks are reported, never silently skipped.
116
+ */
117
+ export {
118
+ type PlacementCheckContext,
119
+ type PlacementCheckId,
120
+ type PlacementCheckReport,
121
+ type PlacementCheckSeverity,
122
+ type PlacementIssue,
123
+ type UnverifiableCheck,
124
+ checkPlacements,
125
+ } from './placementChecks.ts'
126
+
127
+ /**
128
+ * The wire engine — the pure planner and its DOM adapter, also Phase 4.
129
+ * `attachWireEngine` writes only through `setMicroDotAttribute`.
130
+ */
131
+ export {
132
+ type WireDelivery,
133
+ type WireEngine,
134
+ type WireEngineOptions,
135
+ type WireEventInput,
136
+ type WireOutcome,
137
+ type WirePlan,
138
+ type WireSkipReason,
139
+ type WireTrace,
140
+ type WireWrite,
141
+ applyTransform,
142
+ attachWireEngine,
143
+ planWires,
144
+ } from './wireEngine.ts'
package/src/loader.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { type MicroDotEntry, apiUrlFor } from './registry.ts'
2
+
3
+ /**
4
+ * Loads a MicroDot bundle and mounts an instance of its element.
5
+ *
6
+ * The bundle registers the custom element as a side effect of being imported,
7
+ * so a host only waits for the module and for `customElements.whenDefined`.
8
+ */
9
+ export const loadMicroDot = async (
10
+ bundleUrl: string,
11
+ tag: string,
12
+ ): Promise<void> => {
13
+ if (customElements.get(tag) === undefined) {
14
+ await import(/* @vite-ignore */ bundleUrl)
15
+ await customElements.whenDefined(tag)
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Creates a configured element WITHOUT a registry.
21
+ *
22
+ * The registry-free half, because a page that embeds exactly one MicroDot does
23
+ * not need a manifest — it needs the same two things every host needs: fetch the
24
+ * built bundle, then configure the element through attributes. `apps/host` uses
25
+ * `createMicroDotFromEntry` below; `apps/cross-origin-demo` uses this.
26
+ *
27
+ * `api-url` is set BEFORE the element enters the document: it is deliberately
28
+ * not an observed attribute, so `defineMicroDot` reads it once in
29
+ * `connectedCallback` and a later write goes nowhere.
30
+ *
31
+ * Every attribute given is written, blank ones included — a registry may
32
+ * deliberately declare `''`. Dropping blanks is a rule about OVERRIDES only; see
33
+ * `createMicroDotFromEntry`.
34
+ */
35
+ export const createMicroDot = (
36
+ tag: string,
37
+ apiUrl: string,
38
+ attributes: Readonly<Record<string, string>> = {},
39
+ ): HTMLElement => {
40
+ const element = document.createElement(tag)
41
+ element.setAttribute('api-url', apiUrl)
42
+ Object.entries(attributes).forEach(([name, value]) => {
43
+ element.setAttribute(name, value)
44
+ })
45
+ return element
46
+ }
47
+
48
+ /**
49
+ * The registry-backed convenience: resolve the API URL from the entry, then
50
+ * apply the entry's attributes and any mount-time overrides.
51
+ *
52
+ * `overrides` is for attributes the host only knows at MOUNT time. The registry
53
+ * holds what a MicroDot always gets; this is for what depends on the browser it
54
+ * is being mounted into — a remembered interview id, say. Applied last so an
55
+ * override wins.
56
+ *
57
+ * **An EMPTY override is dropped before the merge, not after.** "I looked and
58
+ * found nothing" must leave the registry's value standing, and an override of
59
+ * `''` merged in first and filtered later would delete it instead. That
60
+ * distinction survived the D1 extraction only because
61
+ * `apps/host/src/loader.test.ts` asserts it — the first version of this function
62
+ * merged then filtered, and turned `symbol: 'FOLD'` into no symbol at all.
63
+ */
64
+ export const createMicroDotFromEntry = (
65
+ entry: MicroDotEntry,
66
+ hostname: string = location.hostname,
67
+ overrides: Readonly<Record<string, string>> = {},
68
+ ): HTMLElement =>
69
+ createMicroDot(entry.tag, apiUrlFor(entry, hostname), {
70
+ ...entry.attributes,
71
+ ...Object.fromEntries(
72
+ Object.entries(overrides).filter(([, value]) => value !== ''),
73
+ ),
74
+ })
75
+
76
+ /**
77
+ * Loads and mounts one MicroDot into a root a host already owns.
78
+ *
79
+ * `replaceChildren` rather than `appendChild`, because the root is a container
80
+ * the host handed over. **Never use this for a DOM anchor** — an anchored
81
+ * placement inserts adjacent to somebody else's element and must not own it.
82
+ * See `wiki/framework/mounting/anchor-mounting-into-host-owned-dom.md`.
83
+ */
84
+ export const mountMicroDot = async ({
85
+ tag,
86
+ bundleUrl,
87
+ apiUrl,
88
+ root,
89
+ }: {
90
+ readonly tag: string
91
+ readonly bundleUrl: string
92
+ readonly apiUrl: string
93
+ readonly root: HTMLElement
94
+ }): Promise<HTMLElement> => {
95
+ await loadMicroDot(bundleUrl, tag)
96
+ const element = createMicroDot(tag, apiUrl)
97
+ root.replaceChildren(element)
98
+ return element
99
+ }
100
+
101
+ /**
102
+ * NOTE: `setAttribute` fires `attributeChangedCallback` even when the value is
103
+ * unchanged, so an unguarded write driven by a recurring event resets the
104
+ * MicroDot on every tick. **Always route host-driven writes through here.**
105
+ *
106
+ * This was the one function genuinely duplicated between `apps/host` and
107
+ * `apps/cross-origin-demo` — byte for byte, comment and all. Any wire-execution
108
+ * engine must keep the guard; see
109
+ * `wiki/framework/composition/wire-execution-and-transforms.md`.
110
+ */
111
+ export const setMicroDotAttribute = (
112
+ element: Element,
113
+ name: string,
114
+ value: string,
115
+ ): void => {
116
+ if (element.getAttribute(name) !== value) {
117
+ element.setAttribute(name, value)
118
+ }
119
+ }