@mossbear/protocol 0.1.0-alpha.100
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 +21 -0
- package/README.md +7 -0
- package/dist/agentGuidancePaths.d.ts +101 -0
- package/dist/agentGuidancePaths.d.ts.map +1 -0
- package/dist/agentGuidancePaths.js +185 -0
- package/dist/agentGuidancePaths.js.map +1 -0
- package/dist/agentGuidancePaths.test.d.ts +2 -0
- package/dist/agentGuidancePaths.test.d.ts.map +1 -0
- package/dist/agentGuidancePaths.test.js +91 -0
- package/dist/agentGuidancePaths.test.js.map +1 -0
- package/dist/aliasPaths.d.ts +100 -0
- package/dist/aliasPaths.d.ts.map +1 -0
- package/dist/aliasPaths.js +148 -0
- package/dist/aliasPaths.js.map +1 -0
- package/dist/aliasPaths.test.d.ts +2 -0
- package/dist/aliasPaths.test.d.ts.map +1 -0
- package/dist/aliasPaths.test.js +80 -0
- package/dist/aliasPaths.test.js.map +1 -0
- package/dist/artifact.test.d.ts +2 -0
- package/dist/artifact.test.d.ts.map +1 -0
- package/dist/artifact.test.js +374 -0
- package/dist/artifact.test.js.map +1 -0
- package/dist/bundleSlug.d.ts +177 -0
- package/dist/bundleSlug.d.ts.map +1 -0
- package/dist/bundleSlug.js +233 -0
- package/dist/bundleSlug.js.map +1 -0
- package/dist/bundleSlug.test.d.ts +2 -0
- package/dist/bundleSlug.test.d.ts.map +1 -0
- package/dist/bundleSlug.test.js +197 -0
- package/dist/bundleSlug.test.js.map +1 -0
- package/dist/commentAnchor.d.ts +34 -0
- package/dist/commentAnchor.d.ts.map +1 -0
- package/dist/commentAnchor.js +122 -0
- package/dist/commentAnchor.js.map +1 -0
- package/dist/commentAnchor.test.d.ts +2 -0
- package/dist/commentAnchor.test.d.ts.map +1 -0
- package/dist/commentAnchor.test.js +48 -0
- package/dist/commentAnchor.test.js.map +1 -0
- package/dist/contextKinds.d.ts +165 -0
- package/dist/contextKinds.d.ts.map +1 -0
- package/dist/contextKinds.js +148 -0
- package/dist/contextKinds.js.map +1 -0
- package/dist/contextKinds.test.d.ts +2 -0
- package/dist/contextKinds.test.d.ts.map +1 -0
- package/dist/contextKinds.test.js +137 -0
- package/dist/contextKinds.test.js.map +1 -0
- package/dist/frameDocument.d.ts +71 -0
- package/dist/frameDocument.d.ts.map +1 -0
- package/dist/frameDocument.js +140 -0
- package/dist/frameDocument.js.map +1 -0
- package/dist/frameDocument.test.d.ts +2 -0
- package/dist/frameDocument.test.d.ts.map +1 -0
- package/dist/frameDocument.test.js +84 -0
- package/dist/frameDocument.test.js.map +1 -0
- package/dist/frameProtocol.d.ts +11 -0
- package/dist/frameProtocol.d.ts.map +1 -0
- package/dist/frameProtocol.js +11 -0
- package/dist/frameProtocol.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +19 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +19 -0
- package/dist/limits.js.map +1 -0
- package/dist/markdownSections.d.ts +58 -0
- package/dist/markdownSections.d.ts.map +1 -0
- package/dist/markdownSections.js +102 -0
- package/dist/markdownSections.js.map +1 -0
- package/dist/markdownSections.test.d.ts +2 -0
- package/dist/markdownSections.test.d.ts.map +1 -0
- package/dist/markdownSections.test.js +95 -0
- package/dist/markdownSections.test.js.map +1 -0
- package/dist/pairing.d.ts +183 -0
- package/dist/pairing.d.ts.map +1 -0
- package/dist/pairing.js +175 -0
- package/dist/pairing.js.map +1 -0
- package/dist/pairing.test.d.ts +2 -0
- package/dist/pairing.test.d.ts.map +1 -0
- package/dist/pairing.test.js +105 -0
- package/dist/pairing.test.js.map +1 -0
- package/dist/photos.d.ts +146 -0
- package/dist/photos.d.ts.map +1 -0
- package/dist/photos.js +127 -0
- package/dist/photos.js.map +1 -0
- package/dist/publicModelCatalog.d.ts +19 -0
- package/dist/publicModelCatalog.d.ts.map +1 -0
- package/dist/publicModelCatalog.generated.d.ts +2 -0
- package/dist/publicModelCatalog.generated.d.ts.map +1 -0
- package/dist/publicModelCatalog.generated.js +489 -0
- package/dist/publicModelCatalog.generated.js.map +1 -0
- package/dist/publicModelCatalog.js +68 -0
- package/dist/publicModelCatalog.js.map +1 -0
- package/dist/publicModelCatalog.test.d.ts +2 -0
- package/dist/publicModelCatalog.test.d.ts.map +1 -0
- package/dist/publicModelCatalog.test.js +88 -0
- package/dist/publicModelCatalog.test.js.map +1 -0
- package/dist/publicModelNativeAliases.d.ts +5 -0
- package/dist/publicModelNativeAliases.d.ts.map +1 -0
- package/dist/publicModelNativeAliases.js +8 -0
- package/dist/publicModelNativeAliases.js.map +1 -0
- package/dist/schemas.d.ts +10745 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +4572 -0
- package/dist/schemas.js.map +1 -0
- package/dist/schemas.test.d.ts +2 -0
- package/dist/schemas.test.d.ts.map +1 -0
- package/dist/schemas.test.js +1617 -0
- package/dist/schemas.test.js.map +1 -0
- package/dist/steeringOverTime.d.ts +30 -0
- package/dist/steeringOverTime.d.ts.map +1 -0
- package/dist/steeringOverTime.js +19 -0
- package/dist/steeringOverTime.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/usageOnly.d.ts +190 -0
- package/dist/usageOnly.d.ts.map +1 -0
- package/dist/usageOnly.js +53 -0
- package/dist/usageOnly.js.map +1 -0
- package/dist/usageOnly.test.d.ts +2 -0
- package/dist/usageOnly.test.d.ts.map +1 -0
- package/dist/usageOnly.test.js +203 -0
- package/dist/usageOnly.test.js.map +1 -0
- package/dist/version.d.ts +47 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +125 -0
- package/dist/version.js.map +1 -0
- package/dist/version.test.d.ts +2 -0
- package/dist/version.test.d.ts.map +1 -0
- package/dist/version.test.js +86 -0
- package/dist/version.test.js.map +1 -0
- package/dist/whatSyncs.d.ts +62 -0
- package/dist/whatSyncs.d.ts.map +1 -0
- package/dist/whatSyncs.js +228 -0
- package/dist/whatSyncs.js.map +1 -0
- package/dist/whatSyncs.test.d.ts +2 -0
- package/dist/whatSyncs.test.d.ts.map +1 -0
- package/dist/whatSyncs.test.js +113 -0
- package/dist/whatSyncs.test.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one table the context item-kind narrowings derive from.
|
|
3
|
+
*
|
|
4
|
+
* **Why this file exists.** What an agent may *read* back
|
|
5
|
+
* (`ContextItemTypeSchema`) and what it may *capture* into the inbox
|
|
6
|
+
* (`CaptureContentTypeSchema`) are two narrowings of the same question, plus a lossy
|
|
7
|
+
* kind → item-type mapping and a
|
|
8
|
+
* SQL inverse of it in the items route. Each narrowing had a reason and none of
|
|
9
|
+
* them derived from a shared source, so adding a fourth kind meant editing five
|
|
10
|
+
* places and nothing failed if you missed one.
|
|
11
|
+
*
|
|
12
|
+
* Now one row per kind answers all of it declaratively. A new kind is a new row
|
|
13
|
+
* that must state whether it is pushable and capturable; it cannot be added and
|
|
14
|
+
* silently omitted from a narrowing, because no narrowing has its own list any
|
|
15
|
+
* more.
|
|
16
|
+
*
|
|
17
|
+
* `contextKinds.test.ts` pins each derived picklist against a hand-written copy
|
|
18
|
+
* of today's values, so a row edit that would change the wire fails there rather
|
|
19
|
+
* than in a client. Which kinds are pushable and capturable are product
|
|
20
|
+
* decisions this table records; changing one is a separate, deliberate change to
|
|
21
|
+
* that row.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The stored kinds that are addressable as context items on the wire.
|
|
25
|
+
*
|
|
26
|
+
* **Keyed on the `(role, format)` pair, and that is the load-bearing part.**
|
|
27
|
+
* A table keyed on `role` alone would quietly hand a
|
|
28
|
+
* **script** — `content` + `code` — both `pushable` and `capturable`, because
|
|
29
|
+
* nothing would separate it from a markdown document. It must not, and the pair
|
|
30
|
+
* is what stops it. This is the one place the two columns have to be read
|
|
31
|
+
* together; splitting a column does not by itself make every consumer
|
|
32
|
+
* single-column.
|
|
33
|
+
*
|
|
34
|
+
* Pairs *not* listed — `guidance`, `criteria`, `content` + `code`, and a row
|
|
35
|
+
* with no role at all — are still stored. They collapse onto
|
|
36
|
+
* {@link DEFAULT_CONTEXT_ITEM_TYPE} when serialized, and
|
|
37
|
+
* {@link kindFilterForItemTypes} is what keeps SQL agreeing with that.
|
|
38
|
+
*
|
|
39
|
+
* Order is the wire order of the derived picklists and is load-bearing for the
|
|
40
|
+
* pin test; append rather than reorder.
|
|
41
|
+
*/
|
|
42
|
+
export const CONTEXT_CONTENT_KINDS = [
|
|
43
|
+
{
|
|
44
|
+
itemType: 'content',
|
|
45
|
+
role: 'content',
|
|
46
|
+
format: 'markdown',
|
|
47
|
+
pushable: true,
|
|
48
|
+
capturable: true,
|
|
49
|
+
},
|
|
50
|
+
// `capturable` ahead of the upload path it is for: the inbox schema has
|
|
51
|
+
// admitted `asset` since it was written, with image upload still to land.
|
|
52
|
+
// The flag records today's wire, which is the only thing this table is
|
|
53
|
+
// allowed to record.
|
|
54
|
+
{
|
|
55
|
+
itemType: 'asset',
|
|
56
|
+
role: 'content',
|
|
57
|
+
format: 'binary',
|
|
58
|
+
pushable: true,
|
|
59
|
+
capturable: true,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* The item type of a `guides` row.
|
|
64
|
+
*
|
|
65
|
+
* A guide is not a stored `(role, format)` pair at all — it is a different
|
|
66
|
+
* table — which is why it is named here rather than added to the table above. It
|
|
67
|
+
* is readable as an item and deliberately not capturable.
|
|
68
|
+
*/
|
|
69
|
+
export const GUIDE_ITEM_TYPE = 'guide';
|
|
70
|
+
/**
|
|
71
|
+
* What an unlisted pair serializes as.
|
|
72
|
+
*
|
|
73
|
+
* The default arm exists so a stray row — one written before a kind was
|
|
74
|
+
* retired, or by a non-context surface — produces a schema-valid response
|
|
75
|
+
* instead of failing the read. It is what makes the mapping lossy, and so what
|
|
76
|
+
* forces {@link kindFilterForItemTypes} to exist.
|
|
77
|
+
*/
|
|
78
|
+
export const DEFAULT_CONTEXT_ITEM_TYPE = 'content';
|
|
79
|
+
// `Extract` rather than a bare boolean `filter`, because a bare one widens.
|
|
80
|
+
// `k.pushable` does not narrow `k`, so the derived arrays would type as *every*
|
|
81
|
+
// content type and `CaptureContentType` would silently admit `reference` at the
|
|
82
|
+
// type level while still rejecting it at runtime — a wire narrowing that no
|
|
83
|
+
// longer narrows anything a compiler can see. The predicate keeps each derived
|
|
84
|
+
// picklist as tight as the literal it replaced.
|
|
85
|
+
const kindsWhere = (flag) => CONTEXT_CONTENT_KINDS.filter((k) => k[flag]).map((k) => k.itemType);
|
|
86
|
+
/** Item types a stored kind can serialize as, in wire order. */
|
|
87
|
+
export const CONTEXT_CONTENT_TYPES = CONTEXT_CONTENT_KINDS.map((k) => k.itemType);
|
|
88
|
+
/** Item types an agent may read back, in wire order. */
|
|
89
|
+
export const CONTEXT_ITEM_TYPES = [GUIDE_ITEM_TYPE, ...CONTEXT_CONTENT_TYPES];
|
|
90
|
+
/**
|
|
91
|
+
* Everything `?types=` parses.
|
|
92
|
+
*
|
|
93
|
+
* The same list a read serializes, now that nothing is accepted under a
|
|
94
|
+
* retired name: `document` was mapped through for one release so a filter
|
|
95
|
+
* written against the old vocabulary returned a superset rather than an
|
|
96
|
+
* empty page, and that window closed with the release that moved the CLI's
|
|
97
|
+
* own vocabulary — the same shape `reference`'s retirement closed under (git
|
|
98
|
+
* history has that window's open and close).
|
|
99
|
+
*/
|
|
100
|
+
export const CONTEXT_ITEM_TYPE_FILTER_VALUES = CONTEXT_ITEM_TYPES;
|
|
101
|
+
/** Values the inbox may capture. */
|
|
102
|
+
export const CAPTURE_CONTENT_TYPES = kindsWhere('capturable');
|
|
103
|
+
/**
|
|
104
|
+
* The item type a stored kind serializes as.
|
|
105
|
+
*
|
|
106
|
+
* Anything unrecognized — a guidance row, a rubric, a script, an `html` page, a
|
|
107
|
+
* row carrying no role at all — is a {@link DEFAULT_CONTEXT_ITEM_TYPE}, so a
|
|
108
|
+
* stray row never produces a schema-invalid response. That default is what
|
|
109
|
+
* makes this mapping non-injective: the pair cannot be recovered from an item's
|
|
110
|
+
* `type`, which is why filtering by type in SQL needs
|
|
111
|
+
* {@link kindFilterForItemTypes} rather than an inverted lookup.
|
|
112
|
+
*/
|
|
113
|
+
export function itemTypeForKind(role, format) {
|
|
114
|
+
const kind = CONTEXT_CONTENT_KINDS.find((k) => k.role === role && k.format === format);
|
|
115
|
+
return kind ? kind.itemType : DEFAULT_CONTEXT_ITEM_TYPE;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The item type a bundle read's item is, whether or not the server sent `type`.
|
|
119
|
+
*
|
|
120
|
+
* `type` is leaving the wire, and everything it said is already on the item: a
|
|
121
|
+
* guide is a `guides` row, so it is the only live item with no `(role, format)`
|
|
122
|
+
* pair at all. A tombstone also reports both as null, and says `removed`; an
|
|
123
|
+
* alias never travels as an item of its own. Every other item's type is
|
|
124
|
+
* {@link itemTypeForKind} of its pair, which is how the server derives it.
|
|
125
|
+
*/
|
|
126
|
+
export function contextItemTypeOf(item) {
|
|
127
|
+
if (item.type !== undefined)
|
|
128
|
+
return item.type;
|
|
129
|
+
if (item.role === null && item.format === null && item.removed !== true) {
|
|
130
|
+
return GUIDE_ITEM_TYPE;
|
|
131
|
+
}
|
|
132
|
+
return itemTypeForKind(item.role, item.format);
|
|
133
|
+
}
|
|
134
|
+
export function kindFilterForItemTypes(wantedItemTypes) {
|
|
135
|
+
const wanted = new Set(wantedItemTypes);
|
|
136
|
+
const kinds = CONTEXT_CONTENT_KINDS.filter((k) => wanted.has(k.itemType)).map((k) => ({ role: k.role, format: k.format }));
|
|
137
|
+
if (!wanted.has(DEFAULT_CONTEXT_ITEM_TYPE))
|
|
138
|
+
return { kind: 'in', kinds };
|
|
139
|
+
return {
|
|
140
|
+
kind: 'inOrUnlisted',
|
|
141
|
+
kinds,
|
|
142
|
+
// The listed kinds that are *not* the default — i.e. every pair whose item
|
|
143
|
+
// type is something other than `content`. A row outside this set reads back
|
|
144
|
+
// as `content` by the default arm above, a tombstone's two NULLs included.
|
|
145
|
+
excluding: CONTEXT_CONTENT_KINDS.filter((k) => k.itemType !== DEFAULT_CONTEXT_ITEM_TYPE).map((k) => ({ role: k.role, format: k.format })),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=contextKinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextKinds.js","sourceRoot":"","sources":["../src/contextKinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC;QACE,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;KACjB;IACD,wEAAwE;IACxE,0EAA0E;IAC1E,uEAAuE;IACvE,qBAAqB;IACrB;QACE,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;KACjB;CACO,CAAA;AAEV;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAA;AAOlD,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,gDAAgD;AAChD,MAAM,UAAU,GAAG,CAA0C,IAAW,EAAE,EAAE,CAC1E,qBAAqB,CAAC,MAAM,CAC1B,CAAC,CAAC,EAAyD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,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pC,eAAiC;IAEjC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;IACvC,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAC3E,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CACzD,CAAA;IACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IACxE,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,KAAK;QACL,2EAA2E;QAC3E,4EAA4E;QAC5E,2EAA2E;QAC3E,SAAS,EAAE,qBAAqB,CAAC,MAAM,CACrC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,yBAAyB,CAChD,CAAC,GAAG,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;KAChE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextKinds.test.d.ts","sourceRoot":"","sources":["../src/contextKinds.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { CONTEXT_CONTENT_TYPES, CONTEXT_ITEM_TYPE_FILTER_VALUES, CONTEXT_ITEM_TYPES, CAPTURE_CONTENT_TYPES, itemTypeForKind, kindFilterForItemTypes, } from './contextKinds.js';
|
|
4
|
+
import { ContextItemTypeFilterSchema, ContextItemTypeSchema, CaptureContentTypeSchema, } from './schemas.js';
|
|
5
|
+
/**
|
|
6
|
+
* These are pins, not specifications. Each literal below is a hand-written copy
|
|
7
|
+
* of what the wire carries, so a table edit that would change what a client
|
|
8
|
+
* sends or accepts fails here — where the change is visible and deliberate —
|
|
9
|
+
* rather than in a released CLI.
|
|
10
|
+
*
|
|
11
|
+
* Editing a literal in this file is therefore a wire change. If that is what you
|
|
12
|
+
* mean, the row in `CONTEXT_CONTENT_KINDS` and the pin move together and the
|
|
13
|
+
* commit says which clients are affected.
|
|
14
|
+
*/
|
|
15
|
+
describe('the derived picklists still carry the values they replaced', () => {
|
|
16
|
+
it('an agent reads back a guide, content or an asset — document is gone', () => {
|
|
17
|
+
// `document` was renamed to `content` — the umbrella noun is `artifact`
|
|
18
|
+
// (D20) and the enum member can no longer claim a guide is not one.
|
|
19
|
+
expect(CONTEXT_ITEM_TYPES).toEqual(['guide', 'content', 'asset']);
|
|
20
|
+
expect(ContextItemTypeSchema.options).toEqual(['guide', 'content', 'asset']);
|
|
21
|
+
});
|
|
22
|
+
it('?types= no longer accepts document — the compatibility window closed', () => {
|
|
23
|
+
expect(CONTEXT_ITEM_TYPE_FILTER_VALUES).toEqual(['guide', 'content', 'asset']);
|
|
24
|
+
expect(ContextItemTypeFilterSchema.options).toEqual(['guide', 'content', 'asset']);
|
|
25
|
+
expect(v.safeParse(ContextItemTypeFilterSchema, 'document').success).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
it('the inbox captures content or an asset — document is refused', () => {
|
|
28
|
+
expect(CAPTURE_CONTENT_TYPES).toEqual(['content', 'asset']);
|
|
29
|
+
expect(CaptureContentTypeSchema.options).toEqual(['content', 'asset']);
|
|
30
|
+
expect(v.safeParse(CaptureContentTypeSchema, 'document').success).toBe(false);
|
|
31
|
+
expect(v.safeParse(CaptureContentTypeSchema, 'reference').success).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
it('membership kinds are a different axis from content kinds', () => {
|
|
34
|
+
// `guide_file` is a table, not an item type, so no content kind may be one.
|
|
35
|
+
expect(CONTEXT_CONTENT_TYPES).not.toContain('guide_file');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('the pair decides, never the role alone', () => {
|
|
39
|
+
it('reads a script as neither pushable nor capturable', () => {
|
|
40
|
+
// The case the plan singles out. `script` is `content` + `code`, and a table
|
|
41
|
+
// keyed on `role` would make it indistinguishable from ordinary markdown
|
|
42
|
+
// content — silently handing it both flags. Asserted on the picklists
|
|
43
|
+
// themselves, because that is where the mistake would show up.
|
|
44
|
+
expect(itemTypeForKind('content', 'code')).toBe('content');
|
|
45
|
+
expect(CAPTURE_CONTENT_TYPES).not.toContain('script');
|
|
46
|
+
const filter = kindFilterForItemTypes(['asset']);
|
|
47
|
+
expect(filter.kinds).not.toContainEqual({ role: 'content', format: 'code' });
|
|
48
|
+
});
|
|
49
|
+
it('separates an asset from content on format alone', () => {
|
|
50
|
+
expect(itemTypeForKind('content', 'binary')).toBe('asset');
|
|
51
|
+
expect(itemTypeForKind('content', 'markdown')).toBe('content');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('an unrecognized kind still reads back as content', () => {
|
|
55
|
+
it.each([
|
|
56
|
+
['guidance', 'markdown'],
|
|
57
|
+
['criteria', 'markdown'],
|
|
58
|
+
['content', 'code'],
|
|
59
|
+
['content', 'html'],
|
|
60
|
+
['something-we-retired', 'markdown'],
|
|
61
|
+
])('%s + %s collapses onto content', (role, format) => {
|
|
62
|
+
expect(itemTypeForKind(role, format)).toBe('content');
|
|
63
|
+
});
|
|
64
|
+
it('a row carrying no kind at all is content too', () => {
|
|
65
|
+
// A tombstone, and an alias. Neither has a word of its own on this surface.
|
|
66
|
+
expect(itemTypeForKind(null, null)).toBe('content');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('filtering by item type selects exactly the rows that serialize as it', () => {
|
|
70
|
+
/** The pairs a real table would hold, tombstone included. */
|
|
71
|
+
const rows = [
|
|
72
|
+
{ label: 'content', role: 'content', format: 'markdown' },
|
|
73
|
+
{ label: 'asset', role: 'content', format: 'binary' },
|
|
74
|
+
{ label: 'instructions', role: 'guidance', format: 'markdown' },
|
|
75
|
+
{ label: 'eval', role: 'criteria', format: 'markdown' },
|
|
76
|
+
{ label: 'script', role: 'content', format: 'code' },
|
|
77
|
+
{ label: 'tombstone', role: null, format: null },
|
|
78
|
+
];
|
|
79
|
+
/** Evaluates a `ContentKindFilter` the way the SQL predicate does. */
|
|
80
|
+
function selects(filter) {
|
|
81
|
+
return (row) => {
|
|
82
|
+
const matches = (k) => k.role === row.role && k.format === row.format;
|
|
83
|
+
if (filter.kind === 'in')
|
|
84
|
+
return filter.kinds.some(matches);
|
|
85
|
+
return filter.kinds.some(matches) || !filter.excluding.some(matches);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const cases = [
|
|
89
|
+
{ wanted: ['asset'], expected: ['asset'] },
|
|
90
|
+
// `content` drags in every unlisted pair and the tombstone, because that
|
|
91
|
+
// is what the serializer calls them.
|
|
92
|
+
{
|
|
93
|
+
wanted: ['content'],
|
|
94
|
+
expected: ['content', 'instructions', 'eval', 'script', 'tombstone'],
|
|
95
|
+
},
|
|
96
|
+
{ wanted: ['content', 'asset'], expected: rows.map((r) => r.label) },
|
|
97
|
+
// A guide is not a `guide_files` row at all, so no kind matches.
|
|
98
|
+
{ wanted: ['guide'], expected: [] },
|
|
99
|
+
{ wanted: [], expected: [] },
|
|
100
|
+
// A value outside this function's vocabulary matches no kind — including
|
|
101
|
+
// the retired `reference` and `document`, both of which `?types=` now
|
|
102
|
+
// refuses at `ContextItemTypeFilterSchema` before reaching here, so this
|
|
103
|
+
// is the belt-and-braces arm rather than the one a client can hit.
|
|
104
|
+
{ wanted: ['reference'], expected: [] },
|
|
105
|
+
{ wanted: ['document'], expected: [] },
|
|
106
|
+
];
|
|
107
|
+
it.each(cases)('?types=$wanted matches the rows the serializer agrees with', (c) => {
|
|
108
|
+
const matches = rows.filter(selects(kindFilterForItemTypes(c.wanted)));
|
|
109
|
+
expect(matches.map((r) => r.label)).toEqual(c.expected);
|
|
110
|
+
});
|
|
111
|
+
it('never returns a row whose item type the caller did not ask for', () => {
|
|
112
|
+
for (const c of cases) {
|
|
113
|
+
for (const row of rows.filter(selects(kindFilterForItemTypes(c.wanted)))) {
|
|
114
|
+
expect(c.wanted).toContain(itemTypeForKind(row.role, row.format));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
it('returns every row whose item type the caller did ask for', () => {
|
|
119
|
+
for (const c of cases) {
|
|
120
|
+
const matched = rows.filter(selects(kindFilterForItemTypes(c.wanted)));
|
|
121
|
+
for (const row of rows) {
|
|
122
|
+
if (c.wanted.includes(itemTypeForKind(row.role, row.format))) {
|
|
123
|
+
expect(matched).toContain(row);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
it('keeps the tombstone reachable, which a plain negation would drop', () => {
|
|
129
|
+
// The NULL trap, restated for two columns. A predicate written as a plain
|
|
130
|
+
// `role != 'content' AND format != 'binary'` is NULL for a tombstone and so
|
|
131
|
+
// drops exactly the rows the serializer still calls `content`.
|
|
132
|
+
const filter = kindFilterForItemTypes(['content']);
|
|
133
|
+
const tombstone = rows.find((r) => r.label === 'tombstone');
|
|
134
|
+
expect(selects(filter)(tombstone)).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=contextKinds.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextKinds.test.js","sourceRoot":"","sources":["../src/contextKinds.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACL,qBAAqB,EACrB,+BAA+B,EAC/B,kBAAkB,EAClB,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AAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;oBAC7D,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,0EAA0E;QAC1E,4EAA4E;QAC5E,+DAA+D;QAC/D,MAAM,MAAM,GAAG,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,WAAW,CAAE,CAAA;QAE5D,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTML document an agent-written `html` artifact runs in, built the same
|
|
3
|
+
* way wherever Mossbear runs one: the dashboard's sandboxed frame and the CLI's
|
|
4
|
+
* `mossbear artifacts preview` both call this function, so what an agent
|
|
5
|
+
* previews is what a reader sees (the live HTML frames plan, *The document*).
|
|
6
|
+
*
|
|
7
|
+
* The page arrives as untrusted HTML and is placed, unmodified, after a fixed
|
|
8
|
+
* `<head>` this function owns. The head comes first so its policy and its shell
|
|
9
|
+
* script are in force before a single byte of the page is parsed: a
|
|
10
|
+
* Content-Security-Policy `<meta>` binds only the content after it, and the
|
|
11
|
+
* shell must replace storage before the page's own scripts reach for it.
|
|
12
|
+
*
|
|
13
|
+
* A page that is a whole document (`<!doctype html><html><head>…`) needs no
|
|
14
|
+
* unwrapping. Inside `<body>` the parser drops a second doctype, `<head>` and
|
|
15
|
+
* `<body>` tag, keeps its children in place, and merges `<html>` attributes
|
|
16
|
+
* only where ours left them unset — so the page's `<style>`, `<link>` and
|
|
17
|
+
* `<script>` still apply, and a CSP `<meta>` of its own, now outside the head,
|
|
18
|
+
* cannot loosen ours (a later policy can only ever add restrictions anyway).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The `sandbox` attribute of every frame that runs one of these documents.
|
|
22
|
+
* Scripts and nothing else: no `allow-same-origin`, so the frame's origin is
|
|
23
|
+
* opaque and it can read no cookie, storage or page of its host; no
|
|
24
|
+
* `allow-forms`, `allow-popups`, `allow-top-navigation` or `allow-modals`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const FRAME_SANDBOX = "allow-scripts";
|
|
27
|
+
/** The frame's `referrerpolicy`: a request it does make names no host page. */
|
|
28
|
+
export declare const FRAME_REFERRER_POLICY = "no-referrer";
|
|
29
|
+
/**
|
|
30
|
+
* The widest the dashboard draws a frame, in CSS pixels: its reading column
|
|
31
|
+
* less the page's padding and the frame's border. A narrower window draws it
|
|
32
|
+
* narrower. The CLI's preview uses it as its default width, and a dashboard
|
|
33
|
+
* end-to-end test measures the real frame against it, so the two cannot drift.
|
|
34
|
+
*/
|
|
35
|
+
export declare const FRAME_READING_WIDTH = 1062;
|
|
36
|
+
/**
|
|
37
|
+
* Hosts a page may load code from: the CDNs Claude's own artifacts allow, so a
|
|
38
|
+
* design built there renders here unchanged (founder decision, 2026-10-16).
|
|
39
|
+
*/
|
|
40
|
+
export declare const FRAME_SCRIPT_HOSTS: readonly ["https://cdnjs.cloudflare.com", "https://cdn.jsdelivr.net/npm/", "https://unpkg.com", "https://cdn.tailwindcss.com", "https://code.jquery.com"];
|
|
41
|
+
/**
|
|
42
|
+
* The policy every frame runs under.
|
|
43
|
+
*
|
|
44
|
+
* - `connect-src 'none'` (by `default-src`): a page loads code but cannot fetch,
|
|
45
|
+
* XHR, open a WebSocket or send a beacon. Images are limited to inline data
|
|
46
|
+
* for the same reason: a remote `<img>` is a request. **CSP does not govern
|
|
47
|
+
* navigation**, so a page that navigates itself can still carry its own
|
|
48
|
+
* content out in the URL; the dashboard ends the frame when that load lands,
|
|
49
|
+
* and the live HTML frames plan's *Navigation ends the frame* states that
|
|
50
|
+
* residual window. The frame holds nothing of the dashboard's to carry.
|
|
51
|
+
* - `'unsafe-eval'` beside `'unsafe-inline'`: inline script is the whole point
|
|
52
|
+
* of a prototype, and in-browser JSX and template compilers need eval. Eval
|
|
53
|
+
* grants nothing inline script did not.
|
|
54
|
+
* - `base-uri 'none'` and `form-action 'none'`: no `<base>` repointing relative
|
|
55
|
+
* URLs, no form posting anywhere (the sandbox also withholds `allow-forms`).
|
|
56
|
+
*/
|
|
57
|
+
export declare const FRAME_CSP: string;
|
|
58
|
+
export type FrameTheme = 'light' | 'dark';
|
|
59
|
+
export type FrameDocumentOptions = {
|
|
60
|
+
theme: FrameTheme;
|
|
61
|
+
/**
|
|
62
|
+
* A script of ours to run after the shell and before the page: the
|
|
63
|
+
* dashboard's comment layer, passed in by the caller so this module stays
|
|
64
|
+
* free of it. Trusted code only — it is inlined verbatim, and must not
|
|
65
|
+
* contain a `</script` (the layer's generator refuses one).
|
|
66
|
+
*/
|
|
67
|
+
layer?: string;
|
|
68
|
+
};
|
|
69
|
+
/** Wrap an agent-written page in the frame's fixed head. Pure: same in, same out. */
|
|
70
|
+
export declare function buildFrameDocument(html: string, options: FrameDocumentOptions): string;
|
|
71
|
+
//# sourceMappingURL=frameDocument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameDocument.d.ts","sourceRoot":"","sources":["../src/frameDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAE5C,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,gBAAgB,CAAA;AAElD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,OAAO,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,2JAMrB,CAAA;AAEV;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,QASV,CAAA;AA2DZ,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;AAEzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,UAAU,CAAA;IACjB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAWtF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTML document an agent-written `html` artifact runs in, built the same
|
|
3
|
+
* way wherever Mossbear runs one: the dashboard's sandboxed frame and the CLI's
|
|
4
|
+
* `mossbear artifacts preview` both call this function, so what an agent
|
|
5
|
+
* previews is what a reader sees (the live HTML frames plan, *The document*).
|
|
6
|
+
*
|
|
7
|
+
* The page arrives as untrusted HTML and is placed, unmodified, after a fixed
|
|
8
|
+
* `<head>` this function owns. The head comes first so its policy and its shell
|
|
9
|
+
* script are in force before a single byte of the page is parsed: a
|
|
10
|
+
* Content-Security-Policy `<meta>` binds only the content after it, and the
|
|
11
|
+
* shell must replace storage before the page's own scripts reach for it.
|
|
12
|
+
*
|
|
13
|
+
* A page that is a whole document (`<!doctype html><html><head>…`) needs no
|
|
14
|
+
* unwrapping. Inside `<body>` the parser drops a second doctype, `<head>` and
|
|
15
|
+
* `<body>` tag, keeps its children in place, and merges `<html>` attributes
|
|
16
|
+
* only where ours left them unset — so the page's `<style>`, `<link>` and
|
|
17
|
+
* `<script>` still apply, and a CSP `<meta>` of its own, now outside the head,
|
|
18
|
+
* cannot loosen ours (a later policy can only ever add restrictions anyway).
|
|
19
|
+
*/
|
|
20
|
+
import { FRAME_HOST_MESSAGE_SOURCE, FRAME_MESSAGE_SOURCE } from './frameProtocol.js';
|
|
21
|
+
/**
|
|
22
|
+
* The `sandbox` attribute of every frame that runs one of these documents.
|
|
23
|
+
* Scripts and nothing else: no `allow-same-origin`, so the frame's origin is
|
|
24
|
+
* opaque and it can read no cookie, storage or page of its host; no
|
|
25
|
+
* `allow-forms`, `allow-popups`, `allow-top-navigation` or `allow-modals`.
|
|
26
|
+
*/
|
|
27
|
+
export const FRAME_SANDBOX = 'allow-scripts';
|
|
28
|
+
/** The frame's `referrerpolicy`: a request it does make names no host page. */
|
|
29
|
+
export const FRAME_REFERRER_POLICY = 'no-referrer';
|
|
30
|
+
/**
|
|
31
|
+
* The widest the dashboard draws a frame, in CSS pixels: its reading column
|
|
32
|
+
* less the page's padding and the frame's border. A narrower window draws it
|
|
33
|
+
* narrower. The CLI's preview uses it as its default width, and a dashboard
|
|
34
|
+
* end-to-end test measures the real frame against it, so the two cannot drift.
|
|
35
|
+
*/
|
|
36
|
+
export const FRAME_READING_WIDTH = 1062;
|
|
37
|
+
/**
|
|
38
|
+
* Hosts a page may load code from: the CDNs Claude's own artifacts allow, so a
|
|
39
|
+
* design built there renders here unchanged (founder decision, 2026-10-16).
|
|
40
|
+
*/
|
|
41
|
+
export const FRAME_SCRIPT_HOSTS = [
|
|
42
|
+
'https://cdnjs.cloudflare.com',
|
|
43
|
+
'https://cdn.jsdelivr.net/npm/',
|
|
44
|
+
'https://unpkg.com',
|
|
45
|
+
'https://cdn.tailwindcss.com',
|
|
46
|
+
'https://code.jquery.com',
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* The policy every frame runs under.
|
|
50
|
+
*
|
|
51
|
+
* - `connect-src 'none'` (by `default-src`): a page loads code but cannot fetch,
|
|
52
|
+
* XHR, open a WebSocket or send a beacon. Images are limited to inline data
|
|
53
|
+
* for the same reason: a remote `<img>` is a request. **CSP does not govern
|
|
54
|
+
* navigation**, so a page that navigates itself can still carry its own
|
|
55
|
+
* content out in the URL; the dashboard ends the frame when that load lands,
|
|
56
|
+
* and the live HTML frames plan's *Navigation ends the frame* states that
|
|
57
|
+
* residual window. The frame holds nothing of the dashboard's to carry.
|
|
58
|
+
* - `'unsafe-eval'` beside `'unsafe-inline'`: inline script is the whole point
|
|
59
|
+
* of a prototype, and in-browser JSX and template compilers need eval. Eval
|
|
60
|
+
* grants nothing inline script did not.
|
|
61
|
+
* - `base-uri 'none'` and `form-action 'none'`: no `<base>` repointing relative
|
|
62
|
+
* URLs, no form posting anywhere (the sandbox also withholds `allow-forms`).
|
|
63
|
+
*/
|
|
64
|
+
export const FRAME_CSP = [
|
|
65
|
+
"default-src 'none'",
|
|
66
|
+
`script-src 'unsafe-inline' 'unsafe-eval' ${FRAME_SCRIPT_HOSTS.join(' ')}`,
|
|
67
|
+
"style-src 'unsafe-inline' https://fonts.googleapis.com",
|
|
68
|
+
'font-src data: https://fonts.gstatic.com',
|
|
69
|
+
'img-src data: blob:',
|
|
70
|
+
'media-src data: blob:',
|
|
71
|
+
"base-uri 'none'",
|
|
72
|
+
"form-action 'none'",
|
|
73
|
+
].join('; ');
|
|
74
|
+
/**
|
|
75
|
+
* Only the color scheme follows the app's theme: form controls, scrollbars and
|
|
76
|
+
* the default canvas match it, and everything else is the page's own styling.
|
|
77
|
+
*/
|
|
78
|
+
const BASE_CSS = [
|
|
79
|
+
':root{color-scheme:light}',
|
|
80
|
+
':root[data-theme="dark"]{color-scheme:dark}',
|
|
81
|
+
'body{font-family:system-ui,-apple-system,"Segoe UI",sans-serif;background:Canvas;color:CanvasText}',
|
|
82
|
+
].join('');
|
|
83
|
+
/**
|
|
84
|
+
* Runs before the page. ES5 on purpose: it is a string, so no build step
|
|
85
|
+
* transforms it, and it must parse in every browser the dashboard supports.
|
|
86
|
+
*
|
|
87
|
+
* - **Storage lives in memory and dies with the frame.** The frame's origin is
|
|
88
|
+
* opaque, where touching `localStorage` throws, and agent-written prototypes
|
|
89
|
+
* reach for it constantly. An artifact is given no stored state.
|
|
90
|
+
* - **Links are inert**, except jumps within the page. A navigation replaces
|
|
91
|
+
* this document with one that carries none of this policy; the dashboard
|
|
92
|
+
* catches every other path to one by counting the frame's loads.
|
|
93
|
+
* - **Height and the first error go to the host**, and nothing else does.
|
|
94
|
+
* Height is the root's box, not `scrollHeight`, which never reports less
|
|
95
|
+
* than the frame's own height and so could only ever grow it.
|
|
96
|
+
* - **The theme arrives as a message** from the parent window, so a theme
|
|
97
|
+
* change flips `data-theme` without restarting the page.
|
|
98
|
+
*/
|
|
99
|
+
const SHELL_SCRIPT = `(function(){
|
|
100
|
+
var S=${JSON.stringify(FRAME_MESSAGE_SOURCE)};
|
|
101
|
+
function post(m){m.source=S;try{parent.postMessage(m,'*')}catch(e){}}
|
|
102
|
+
function memory(){var d=Object.create(null);return{
|
|
103
|
+
getItem:function(k){k=String(k);return k in d?d[k]:null},
|
|
104
|
+
setItem:function(k,v){d[String(k)]=String(v)},
|
|
105
|
+
removeItem:function(k){delete d[String(k)]},
|
|
106
|
+
clear:function(){d=Object.create(null)},
|
|
107
|
+
key:function(i){var ks=Object.keys(d);return i<ks.length?ks[i]:null},
|
|
108
|
+
get length(){return Object.keys(d).length}}}
|
|
109
|
+
['localStorage','sessionStorage'].forEach(function(n){
|
|
110
|
+
try{Object.defineProperty(window,n,{value:memory(),configurable:true})}catch(e){}});
|
|
111
|
+
document.addEventListener('click',function(e){
|
|
112
|
+
var a=e.target&&e.target.closest?e.target.closest('a'):null;
|
|
113
|
+
if(!a)return;var h=a.getAttribute('href')||a.getAttribute('xlink:href')||'';
|
|
114
|
+
if(h.charAt(0)==='#')return;e.preventDefault()},true);
|
|
115
|
+
var reported=false;
|
|
116
|
+
function fail(m){if(reported)return;reported=true;post({type:'error',message:String(m||'Error').slice(0,300)})}
|
|
117
|
+
window.addEventListener('error',function(e){fail(e.message)});
|
|
118
|
+
window.addEventListener('unhandledrejection',function(e){var r=e.reason;fail(r&&r.message?r.message:r)});
|
|
119
|
+
var last=-1;
|
|
120
|
+
function report(){var h=Math.ceil(document.documentElement.getBoundingClientRect().height);if(h!==last){last=h;post({type:'height',height:h})}}
|
|
121
|
+
var H=${JSON.stringify(FRAME_HOST_MESSAGE_SOURCE)};
|
|
122
|
+
window.addEventListener('message',function(e){var d=e.data;
|
|
123
|
+
if(e.source!==parent||!d||d.source!==H||d.type!=='theme')return;
|
|
124
|
+
if(d.theme==='dark'||d.theme==='light')document.documentElement.setAttribute('data-theme',d.theme)});
|
|
125
|
+
function watch(){report();if(window.ResizeObserver){var o=new ResizeObserver(report);o.observe(document.documentElement);if(document.body)o.observe(document.body)}}
|
|
126
|
+
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',watch);else watch();
|
|
127
|
+
window.addEventListener('load',report);
|
|
128
|
+
})();`;
|
|
129
|
+
/** Wrap an agent-written page in the frame's fixed head. Pure: same in, same out. */
|
|
130
|
+
export function buildFrameDocument(html, options) {
|
|
131
|
+
return (`<!doctype html><html data-theme="${options.theme}"><head>` +
|
|
132
|
+
`<meta http-equiv="Content-Security-Policy" content="${FRAME_CSP}">` +
|
|
133
|
+
'<meta charset="utf-8">' +
|
|
134
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">' +
|
|
135
|
+
`<style>${BASE_CSS}</style>` +
|
|
136
|
+
`<script>${SHELL_SCRIPT}</script>` +
|
|
137
|
+
(options.layer ? `<script>${options.layer}</script>` : '') +
|
|
138
|
+
`</head><body>${html}</body></html>`);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=frameDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameDocument.js","sourceRoot":"","sources":["../src/frameDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEpF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAA;AAE5C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAA;AAElD;;;;;GAKG;AACH,MAAM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frameDocument.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { FRAME_CSP, FRAME_REFERRER_POLICY, FRAME_SANDBOX, FRAME_SCRIPT_HOSTS, buildFrameDocument, } from './frameDocument.js';
|
|
3
|
+
import { FRAME_HOST_MESSAGE_SOURCE, FRAME_MESSAGE_SOURCE } from './frameProtocol.js';
|
|
4
|
+
const page = '<script>window.ran = true</script><h1>Prototype</h1>';
|
|
5
|
+
describe('buildFrameDocument', () => {
|
|
6
|
+
it('puts the policy ahead of every byte of the page', () => {
|
|
7
|
+
const doc = buildFrameDocument(page, { theme: 'light' });
|
|
8
|
+
const policy = doc.indexOf('http-equiv="Content-Security-Policy"');
|
|
9
|
+
expect(policy).toBeGreaterThan(-1);
|
|
10
|
+
expect(policy).toBeLessThan(doc.indexOf('<script>'));
|
|
11
|
+
expect(policy).toBeLessThan(doc.indexOf(page));
|
|
12
|
+
});
|
|
13
|
+
it('runs the shell before the page, so storage is replaced before the page reads it', () => {
|
|
14
|
+
const doc = buildFrameDocument(page, { theme: 'light' });
|
|
15
|
+
expect(doc.indexOf("'localStorage','sessionStorage'")).toBeLessThan(doc.indexOf(page));
|
|
16
|
+
});
|
|
17
|
+
it('runs the comment layer after the shell and before any of the page', () => {
|
|
18
|
+
const layer = 'window.layerRan=1';
|
|
19
|
+
const doc = buildFrameDocument(page, { theme: 'light', layer });
|
|
20
|
+
const shellEnd = doc.indexOf('</script>');
|
|
21
|
+
const layerAt = doc.indexOf(layer);
|
|
22
|
+
expect(layerAt).toBeGreaterThan(shellEnd);
|
|
23
|
+
expect(layerAt).toBeLessThan(doc.indexOf(page));
|
|
24
|
+
expect(doc.indexOf(layer)).toBeGreaterThan(doc.indexOf('Content-Security-Policy'));
|
|
25
|
+
expect(buildFrameDocument(page, { theme: 'light' })).not.toContain('layerRan');
|
|
26
|
+
});
|
|
27
|
+
it('keeps the page byte for byte, a whole document included', () => {
|
|
28
|
+
const whole = '<!doctype html><html><head><title>t</title></head><body>x</body></html>';
|
|
29
|
+
expect(buildFrameDocument(whole, { theme: 'dark' })).toContain(whole);
|
|
30
|
+
});
|
|
31
|
+
it('carries the reader’s theme as the color scheme', () => {
|
|
32
|
+
expect(buildFrameDocument(page, { theme: 'dark' })).toContain('data-theme="dark"');
|
|
33
|
+
expect(buildFrameDocument(page, { theme: 'light' })).toContain('data-theme="light"');
|
|
34
|
+
});
|
|
35
|
+
it('makes links inert apart from jumps within the page, SVG links included', () => {
|
|
36
|
+
const doc = buildFrameDocument(page, { theme: 'light' });
|
|
37
|
+
expect(doc).toContain("addEventListener('click'");
|
|
38
|
+
expect(doc).toContain('preventDefault');
|
|
39
|
+
expect(doc).toContain("getAttribute('xlink:href')");
|
|
40
|
+
});
|
|
41
|
+
it('takes a theme change only from the parent window, without a rebuild', () => {
|
|
42
|
+
const doc = buildFrameDocument(page, { theme: 'light' });
|
|
43
|
+
expect(doc).toContain('e.source!==parent');
|
|
44
|
+
expect(doc).toContain(JSON.stringify(FRAME_HOST_MESSAGE_SOURCE));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('FRAME_CSP', () => {
|
|
48
|
+
const directive = (name) => FRAME_CSP.split('; ').find((part) => part.startsWith(`${name} `));
|
|
49
|
+
it('lets a page send nothing anywhere', () => {
|
|
50
|
+
expect(directive('default-src')).toBe("default-src 'none'");
|
|
51
|
+
expect(directive('connect-src')).toBeUndefined();
|
|
52
|
+
expect(directive('img-src')).toBe('img-src data: blob:');
|
|
53
|
+
expect(directive('form-action')).toBe("form-action 'none'");
|
|
54
|
+
expect(directive('base-uri')).toBe("base-uri 'none'");
|
|
55
|
+
});
|
|
56
|
+
it('loads scripts from exactly the CDNs Claude artifacts allow', () => {
|
|
57
|
+
expect([...FRAME_SCRIPT_HOSTS]).toEqual([
|
|
58
|
+
'https://cdnjs.cloudflare.com',
|
|
59
|
+
'https://cdn.jsdelivr.net/npm/',
|
|
60
|
+
'https://unpkg.com',
|
|
61
|
+
'https://cdn.tailwindcss.com',
|
|
62
|
+
'https://code.jquery.com',
|
|
63
|
+
]);
|
|
64
|
+
for (const host of FRAME_SCRIPT_HOSTS)
|
|
65
|
+
expect(directive('script-src')).toContain(host);
|
|
66
|
+
expect(directive('script-src')).not.toContain('https:;');
|
|
67
|
+
expect(directive('script-src')).not.toMatch(/\s\*(\s|$)/);
|
|
68
|
+
});
|
|
69
|
+
it('takes stylesheets and fonts from Google Fonts only', () => {
|
|
70
|
+
expect(directive('style-src')).toBe("style-src 'unsafe-inline' https://fonts.googleapis.com");
|
|
71
|
+
expect(directive('font-src')).toBe('font-src data: https://fonts.gstatic.com');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('the frame around the document', () => {
|
|
75
|
+
it('lets the page run scripts and gives it no origin, forms, popups or top navigation', () => {
|
|
76
|
+
expect(FRAME_SANDBOX).toBe('allow-scripts');
|
|
77
|
+
expect(FRAME_REFERRER_POLICY).toBe('no-referrer');
|
|
78
|
+
});
|
|
79
|
+
it('posts every message under the frame tag', () => {
|
|
80
|
+
const doc = buildFrameDocument(page, { theme: 'light' });
|
|
81
|
+
expect(doc).toContain(`var S=${JSON.stringify(FRAME_MESSAGE_SOURCE)}`);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=frameDocument.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameDocument.test.js","sourceRoot":"","sources":["../src/frameDocument.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACL,SAAS,EACT,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEpF,MAAM,IAAI,G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